Components disappear after having moved them

Hi again,

I've created a JFrame which looks like this:

[img]http://home.hccnet.nl/f.m.boekhorst/1.JPG[/img]

This is all fine until you hit the big O (maximize). Here is the code I use for the button:

if (source == maximize){

if (this.getBounds().width != (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() & this.getBounds().height != (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()){

this.setBounds(0, 0, (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight());

}else{

this.setBounds(Integer.parseInt(p.getProperty("screen.x_pos")), Integer.parseInt(p.getProperty("screen.y_pos")), Integer.parseInt(p.getProperty("screen.x_bound")), Integer.parseInt(p.getProperty("screen.y_bound")));

}

maximize.setIcon(over_maximize);

updateScreen();

}

And here is the code for updateScreen:

publicvoid updateScreen(){

// Reposition the components

close.setBounds(this.getBounds().width - 23, 0, 23, 26);

maximize.setBounds(this.getBounds().width - 47, 0, 24, 26);

minimize.setBounds(this.getBounds().width - 69, 0, 22, 26);

}

When i hit the maximize button then, it properly resized, and the components are moved. I know they should be visible, but somehow they disappear. Here is a screenshot of what it looks like (i moved the X button to the edge to show you what i'm talking about.

[img]http://home.hccnet.nl/f.m.boekhorst/2.JPG[/img]

What am i doing wrong?

MANY thanks in advance!

[2254 byte] By [lboekhorsta] at [2007-10-2 2:07:58]
# 1

Make better use of LayoutManagers. For example I would use a panel with a BorderLayout for your TitleBar. Then you add a lable with the text to the WEST of the panel. Then you add a panel containing your buttons to the EASE of the panel. When you resize the panel all the adjustments will be done automatically to the CENTER of the panel.

camickra at 2007-7-15 19:49:26 > top of Java-index,Desktop,Core GUI APIs...
# 2

Also I would limit the legth of each line of code. Its hard to read your code when you need to do horizontal scrolling all the time. One way to shorten you code is to do something like the following:

Toolkit toolkit = Toolkit.getDefaultToolkit();

Dimension screen = toolkit.getScreenSize();

Now you can just use: screen.width and screen.height.

camickra at 2007-7-15 19:49:26 > top of Java-index,Desktop,Core GUI APIs...