This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Java Group Boxes

 
Ranch Hand
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Jo Young
Ranch Hand
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, okay, so "group box" is just an ordinary JPanel then.
 
Jo Young
Ranch Hand
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... 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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nevermind I figured it out it has to have an xylayout in order to put stuff where you want it
 
Paul Clapham
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic