• Post Reply Bookmark Topic Watch Topic
  • New Topic

Border Layout in Applet Issues  RSS feed

 
Jeff Hord
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new programmer and doing an assignment for my Java class. I think I am using the right layout, but the components aren't showing up right. They show up in a line all across the top of the applet. I am using the BorderLayout. Please let me know what I am doing wrong. Thank you!
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Swing you don't call "add()" or "setLayout(...)" directly, you'd call those methods on the content pane, like "getContentPane ().add(...)".

I'll move this to the AWT/Swing forum, as there seems nothing applet-specific to the question.
 
Jeff Hord
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:With Swing you don't call "add()" or "setLayout(...)" directly, you'd call those methods on the content pane, like "getContentPane ().add(...)".

I'll move this to the AWT/Swing forum, as there seems nothing applet-specific to the question.



Then I must just be doing it completely wrong. I am trying to make an applet.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant by that is: the question is about layouts, and thus GUIs and Swing in general - which are the same for both applications and applets. The fact that this code is used in an applet makes no difference.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Hord wrote:
Then I must just be doing it completely wrong. I am trying to make an applet.

JApple is a Swing component too. So the same concepts apply to applets.
Check out http://download.oracle.com/javase/tutorial/uiswing/components/applet.html
Notice the line getContentPane().add(label, BorderLayout.CENTER);
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Swing you don't call "add()" or "setLayout(...)" directly, you'd call those methods on the content pane, like "getContentPane ().add(...)".


You don't need getContentPane(). JDK 5 supports this. These methods of a JFrame are directed to the content pane of the frame.

Please let me know what I am doing wrong


The code provided looks fine, so the problem is somewhere else.

Post your SSCCE that demonstrates the problem. And we don't care about your real panels. Just create a simple program that adds 5 different components to each area of the BorderLayout. So your SSCCE should basically be 5 lines of code in the init() method:



There is no need to set the layout specifically since a BorderLayout is used for all top level containers.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
With Swing you don't call "add()" or "setLayout(...)" directly, you'd call those methods on the content pane, like "getContentPane ().add(...)".


You don't need getContentPane(). JDK 5 supports this. These methods of a JFrame are directed to the content pane of the frame.

We're talking about JApplet here, but you're right - since Java 5.0 all of JFrame, JDialog and JApplet redirect calls to add, remove and setLayout to their content pane.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!