File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes newbie help with swing forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "newbie help with swing forms" Watch "newbie help with swing forms" New topic
Author

newbie help with swing forms

john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
I'm new java and swings. I'm trying to create an App where I have a bunch of buttons on a small Panel on the left. Depending on the button that's pressed, it opens the Form on the right side of the App. So far, I'm only able to open the form as a new popup window. Any help on this would be greatly appreciated.

Anyway, here is what I've done so far:
- mainPanel
- JPanel (contains multiple buttons on left side of mainPanel
- created a new - swing gui forms - jDialog form

Then I added the actionPerformed on one of the buttons (mainPanel) with the following code:
JFrame mainFrame = MainSampleForm.getApplication().getMainFrame();
InfoForm if = new InfoForm(mainFrame, false);
if.setVisible(true);
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
You might want to consider having a JPanel on the right that uses the CardLayout. Then the right panel can display other JPanels (cards) depending on the button pressed on the left. A decent tutorial with examples can be found in the Sun Swing tutorials.
john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
i went true the cardlayout and downloaded the source. However, it's kinda hard to compare because it doesn't have the design view where i can see it thru netbeans. I kinda understand the concept of creating the jpanel i'm guessing setting up a listener on that jpanel? However, I'm trying to fully understand it thru the netbeans UI. Would you be able to throw in a few quick steps on how to set that up?
john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
I clicked on Design view and right click on the jPanel2. I then selected "set layout", "card layout". I see the code in the "generated" portion with the following:

jPanel2 = new javax.swing.JPanel();
jPanel2.setName("jPanel2"); // NOI18N
jPanel2.setLayout(new java.awt.CardLayout());

This is where I'm stuck. I want to call another class and when button1 is pressed and have that displayed in jPanel2. Do I right click on "custom code" under the jPanel2 and insert code below the above code block? If so, how do I get from a new instance of the class to having it added to the cardlayout for display?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I'm new java and swings.

so why are you spending all of your time trying to learn an IDE?

your problem is with netbeans, so you'd be better off trying to find a netbeans forum.
john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
Well, the ide is pretty cool. It allows me to setup the forms easily. I just need to understand the cardlayout part of it. Here is a copy of the code in question if that helps. I don't need netbeans steps. All I need is some pointers to where i would modify to support the cardlayout. Thanks in advance.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you really want help, post something that we (the non-netbeans users) can compile and run.

get rid of all the unrelated stuff, possibly
menu's
resourceMap
propertChangeListeners
if it has nothing to do with your cardLayout problem, get rid of it

then you'll have a small program to post here
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
john s murray wrote:Well, the ide is pretty cool. It allows me to setup the forms easily.

but it doesn't let you understand just what you're creating.

I just need to understand the cardlayout part of it.

Case in point.

Solution: dump the netbeans code and go through the Swing tutorials from the ground up. Then you'll be able to understand the tutorial examples and be able to use the constructs contained. Good luck!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10372
    
    8

John,
http://faq.javaranch.com/java/UseCodeTags

You can use the button to modify your existing post.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
sorry about the "[Code]" blocks. I just went in and added them in. Anyway, I only used netbeans as it was recommended. What is everybody using here (eclipse?)? Either way, the "[code]" blocks are now in and if someone can offer some tips on how to edit that code to support the cardlayout, it would be greatly appreciated.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
john s murray wrote:Anyway, I only used netbeans as it was recommended. What is everybody using here (eclipse?)?

It's not whether you use NetBeans or Eclipse or textpad that matters here. What matters is that you're using NetBeans-generated code to learn how to make Swing apps. I know I've overused this example, but that's kind of like ordering a pizza for delivery and hoping that by doing so you'll learn how to cook.

So fine, continue using NetBeans, but if you want to learn Swing, avoid using its drag-and-drop features to create Swing apps. Instead go through the Sun tutorials and learn to create swing by hand. Do this and you won't be disappointed.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I'm trying to create an App where I have a bunch of buttons on a small Panel on the left.
> Depending on the button that's pressed, it opens the Form on the right side of the App.

here's a simple demo of the above.

modify this to do what you want, but if it doesn't work, you will have a small program to post back, for us to look at.

john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
Sorry guys for not getting back. I did order my swing book from amazon and got it last week. I'm trying to read thru a few chapters first before I take a look at the code posted. Hopefully, things will make a little more sense. Will be back in a week or two. Again, thanks for all that posted so far.
john s murray
Ranch Hand

Joined: Apr 26, 2009
Posts: 30
Took longer than I thought. Went thru swing book and things look alot clearer now. I got the cardlayout working using netbeans and all looks good so far. Instead of each card flipping ontop of the other, is there anyway to have a "x" so that the cards can be closed?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie help with swing forms