aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Java Group Boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Group Boxes" Watch "Java Group Boxes" New topic
Author

Java Group Boxes

Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Is there a way to do group boxes in Java? So like if I wanted to have one form that can have multiple different things on it and basically depending on the circumstances control whether they see one box or a different one? I know you can do it in C# but the program I am working on now is in Java. I know of course that I could just have all the aspects of it on top of eachother and then change the visibility of each of them individually as necessary I just figured why do all that if I don't have to. Besides that I'm always up to learn a new better way to do something.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

The phrase "group box" doesn't ring any bells with me. But if you want a form which can show a variety of panels depending on the context, then a CardLayout does that sort of thing.

I don't see why it's an extra burden to keep track of what should be visible; surely no matter what solution you use, you're going to have to say which panel is currently supposed to be visible?

Anyway here's a link to the tutorial: How to Use CardLayout.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495



“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Paul Clapham wrote:The phrase "group box" doesn't ring any bells with me. But if you want a form which can show a variety of panels depending on the context, then a CardLayout does that sort of thing.

I don't see why it's an extra burden to keep track of what should be visible; surely no matter what solution you use, you're going to have to say which panel is currently supposed to be visible?

Anyway here's a link to the tutorial: How to Use CardLayout.



group box is what they are called in C#. And the purpose of a group box is instead of saying for instance:



you can just put 2 group boxes on a form and in one put a 4 labels 3 text boxes and 3 radio buttons and in the other put 3 labels 2 text boxes and 4 radio buttons then have in your code



and do the exact same thing.

group boxes are similar to tabs in that they are (can be) layered but the difference is the user can't see any tab or anything the user can't change which box is showing. As far as the user knows they were all on the same form and you have those 19 lines of code manually showing and hiding each component individually.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Oh, okay, so "group box" is just an ordinary JPanel then.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Paul Clapham wrote:Oh, okay, so "group box" is just an ordinary JPanel then.


Oh so JPanel is what I'm looking for? ok cool thank you
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

... my JPanel keeps moving my components. I put in a JPanel and then tried to put a text field in the JPanel and it wound up being about 3 pixels wide and in the middle of the JPanel.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

nevermind I figured it out it has to have an xylayout in order to put stuff where you want it
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

XYLayout??? No, no, no, read the tutorial about Using Layout Managers. Laying out your components pixel by pixel looks good to beginners because things seem to work right, but you can only really pull it off if you already know how to use layout managers.

Let me move this post to the Swing forum where the real Swing experts hang out.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Paul Clapham wrote:XYLayout??? No, no, no, read the tutorial about Using Layout Managers. Laying out your components pixel by pixel looks good to beginners because things seem to work right, but you can only really pull it off if you already know how to use layout managers.

Let me move this post to the Swing forum where the real Swing experts hang out.


I didn't find any other layout that didn't move my components when I created them. I want to actually see what I put down and where I put it not have it just get crumpled up and stuffed in a corner while I'm putting it down and making sure it's right.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Yeah, that's what all the beginners say. That's until they change the font size or maximize the window or something and find their carefully-laid-out panel now looks like crud. Using a layout manager -- or a combination of layout managers -- is the way to go. But you do have to spend more than half an hour learning about them.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Paul Clapham wrote:Yeah, that's what all the beginners say.


Seeing as I've been working with Java for all of about 6 months and I have basically taught myself everything I know about Java (with of course obviously some help from the internet/forums/books/etc.)... I do believe I'd say Guilty as Charged

but yeah thank you I will take a look at the link you gave me and see if I can figure out how to use the layout managers properly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Group Boxes