• Post Reply Bookmark Topic Watch Topic
  • New Topic

setSize() for Panel has no effect

 
Dewang Shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using two panels in my code. One to show some data, and another one with labels at the bottom of the applet to approximate a JTabbedPane with AWT.
When I check the size of the data panel, it shows the size that I have set. However when I run the applet, the panel is only of size 10x10... What could be the problem?
Even the setBounds() does not position the panel at the specified x,y. Does it require a specific Layout??
//------------ Code ----------
public void init() {
indexPanel = new Panel();
graphPanel = new Panel();
Dimension td = getSize();
int w = td.width;
int h = td.height;
// graphPanel.setSize(w,h-20);
graphPanel.setBounds(0,0,w,h-20);
d = graphPanel.getSize();
System.out.println("getSize() " + graphPanel.getSize());
System.out.println("bounds " + graphPanel.getBounds());

// indexPanel.setSize(w,18);
indexPanel.setBounds(0,h-18,w,18);
add(graphPanel);
add(indexPanel);
}
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dewang,
Yes, for calls to setBounds() and setSize() the LayoutManager of the component you are adding them to must be set to null... for an Applet the default LayoutManager is FlowLayout, so you have to specifically set it to null. Just put the following code in your init() method and everything should work...

HTH,
-Nate
 
Dewang Shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!