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
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.
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);
}
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.
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.