• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

newbie help with swing forms

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,
http://faq.javaranch.com/java/UseCodeTags

You can use the button to modify your existing post.
 
john s murray
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic