File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help with Layout and JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Layout and JDialog" Watch "Help with Layout and JDialog" New topic

Help with Layout and JDialog

Joseph Russell
Ranch Hand

Joined: Jan 08, 2001
Posts: 290
I have a few JDialog's that I need to create which have similiar characteristics.
i.e. one has: Enter ID:__________
Enter Password:__________
Re-enter Password:__________
The next one might have the exact same thing but without the reenter password. There are two others that vary a little more than these two but have some of the same items. In order to simplify the process I was going to create a BasicJDialog class with a few different constructors and methods. Like a addLabel( String s ). That way BasicJDialog is having to do all of the layout work and the calling object only has to tell it what it want's. Okay my question is this. I created this and it works fine with the exception of the method outside the constructor. It compiles fine but during runtime it doesn't add the label I'm calling for. I also took the hasID out and made it a method to call from outside and it works inside the constructor but not when being called from the method.
Here's the code:

Any help would be much appreciated.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Joe,
One problem I see right away is that your method is trying to use genericPane which is only local to your constructor. If you want any other method to use a component then you need to make them class variables. I think that is your entire problem.

I am not sure about your adding the genericPane twice in the dialog. You might have two of them when you are done (i.e. one behind the other!) ...
Joseph Russell
Ranch Hand

Joined: Jan 08, 2001
Posts: 290
Thanks. I also forgot to add:
genericPane = (JPanel) this.getContentPane;
It works now and by the way whether I call genericPane.add(JLabel); once from the method or twice (once in the constructor and method) I get the same result. Although I'm sure it's much cheaper and easier to read with one call...
[This message has been edited by Joseph Russell (edited February 02, 2001).]
I agree. Here's the link:
subject: Help with Layout and JDialog
It's not a secret anymore!