0

This is the code I'm dealing with: http://pastie.org/1501054 When you run this, for some reason, the two panels overlap. Why is this so? Any way I can fix it?

The ActionListener that is provided as an argument is irrelevant to this part of the program.

Also, where can I find a good swing tutorial that uses Eclipse?

mKorbel
  • 109,107
  • 18
  • 130
  • 305

4 Answers4

0

Yes I see the warning label is over lapping the first row

That is because You didnt specify the layout for your contentpane. Heres how you fix it

contentPane.setLayout(new GridLayout(2,1));

add this line under

Container contentPane = getContentPane();

and I think you should change your warning panel to gridlayout 1 and 1 not 0 and 1 because you still have 1 row and 1 column

Xiaoerge
  • 101
  • 1
  • 1
0

When you say you want a good swing tutorial for eclipse, do you want a GUI builder or a tutorial on Swing? Swing is all about layouts. Once you get that down, it's a piece of cake. Just start with flow layouts. If you want a GUI builder, use Netbeans. It's incredible!

As for the overlap, it's not an overlap, but an overwrite. You can only have one panel in BorderLayout.CENTER, the default location. If you want them side by side, do getContentPane().setLayout(new FlowLayout()); Or just add(panel, BorderLayout.SOUTH)

Ryan Amos
  • 5,314
  • 4
  • 34
  • 55
0

While I'm not sure what you want the final result to look like, here's a few of my suggestions.

In the snippet where you add the warning panel to the JFrame

warningPanel.add(warningLabel);
contentPane.add(warningPanel);
pack(); 

contentPane being the container returned by JFrame.getContentPane()

JFrames by default use the BorderLayout, and so,

contentPane.add(<someComponent>)

is identical to

contentPane.add(<someComponent>, BorderLayout.CENTER)

You also add the mainPanel the same way, and you can't have two components with the same constraints, so instead set the warningPanel to BorderLayout.NORTH

contentPane.add(warningPanel, BorderLayout.NORTH)

And also remove the call to pack() in that code snippet, since you call it later on in your code.

Hope this helps.


PS

As for GUI building in Eclipse, this previous question on Eclipse GUI Builder plugins maybe of use. I can't speak for tutorials on using Swing in Eclipse, but a quick google search digs up this tutorial using the Eclipse Visual Editor project

Community
  • 1
  • 1
Zach L
  • 15,692
  • 3
  • 37
  • 39
0

I am not seeing overlapping panes when I run your code. I wonder if you can post a screenshot of the effect that you see.

As for tutorials in Eclipse. I would suggest using Windows Builder pro in Eclipse for building Java GUI. This is an excellent product (free) and very good documentation on the site.

Vincent Ramdhanie
  • 100,586
  • 22
  • 140
  • 187