Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: new to java programming GUI help

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default new to java programming GUI help

    Hey,
    I'm new to programming so sorry if this question is dumb. I've tried googling it but have not found a solution yet.

    I've noticed that on MAC computers setBackground does not work for JButtons. I setOpaque to true but that doesn't really set the background color of the button. Is there any way at all to setBackground for JButtons?

    Also on MAC computers the color WHITE does not seem to work at all, even on a black background . Color.WHITE does not work. Is there a way to get it to work?

    Thanks for the help


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: new to java programming GUI help

    Color.WHITE should work, so you should perhaps provide some context and code which reproduces the problem.

    I recall running into the JButton background issue in the past. Something about how mac and cocoa render the components. The two solutions I came across is to set the look and feel
    [code]
    UIManager.setLookAndFeel("javax.swing.plaf.metal.M etalLookAndFeel");
    [code]
    or create an image that represents what you want and use that as the button icon.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: new to java programming GUI help

    Thank You. I appreciate it. The setBackground for button is now solved. Now for the Color.WHITE

    This is my code. This works on windows os fine. All it does is draw a tictactoe grid and the x's and o's.
    When I run it along with the rest of my code on my mac, it does not draw the tictactoe grid or the x's and o's. I found that if i add the code: g.setColor(Color.WHITE); it still does not work but if its other colors say green it works fine.

    public void draw(Graphics g) {
    // basic tic tac toe grid
    g.drawLine(100,0,100,300);
    g.drawLine(200, 0, 200, 300);

    g.drawLine(0, 100, 300, 100);
    g.drawLine(0,200,300,200);

    // x's and o's
    for (int i = 0; i < 9; i++) {
    if (board[i] == 'X')
    drawX(i,g);
    else if (board[i] == 'O')
    drawO(i,g);
    }

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: new to java programming GUI help

    What is the color of the Graphics object when you enter your draw routine? What is the color of the background? Where are you calling this draw function from? My first guess is that when you enter draw() your graphics color is the same as the background color, and thus you can't see what you draw.

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: new to java programming GUI help

    I don't set a color for the graphics object because when i run it on windows os it works. The lines and x,o is automatically drawn white so i'm guessing it defaults to white??The background color is set to black.
    When running the same exact code on mac os, nothing is drawn.
    If i add g.setColor(Color.WHITE); , nothing is also drawn.
    if i add g.setColor(Color.GREEN); , finally the lines and x,o are drawn in color green.

    So im assuming my problem is with the color white since same code different color works.

Similar Threads

  1. Java 3d Programming
    By Nickthecoder in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2010, 10:48 PM
  2. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 12th, 2010, 08:04 AM
  3. Please help me with this Java programming
    By simply_stunning79 in forum Algorithms & Recursion
    Replies: 1
    Last Post: February 22nd, 2010, 07:48 PM
  4. Towards java programming...
    By emigrant in forum Member Introductions
    Replies: 1
    Last Post: February 15th, 2010, 03:17 AM
  5. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 14th, 2010, 06:42 AM