This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Need a little bit of help stacking buttons

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well I ended up sick today so I missed a class lesson so I do not know how to stack buttons so that once you click one it disappears and another one appears.

I'll be very grateful for help doing this.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you are talking about the CardLayout class. You can read the How to Use CardLayout lesson from the Java Tutorial to learn about it. And you can read more about it in the JavaDoc for the CardLayout.
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
um not to be rude but that went over my head with a few feet to spare, is there a simpler way to do it?
 
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
David,
Are you talking about swing and JButton? If yes the links by Mark should point you in the right direction.
Did you go through them?
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to be honest they're a bit too complicated for me, I've only been programming for about two weeks, and that just goes beyond what I've learned so far
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You never answered Maneesh's question.

David Crane wrote:to be honest they're a bit too complicated for me, I've only been programming for about two weeks, and that just goes beyond what I've learned so far


Then you may wish to not implement this feature and try for something a bit simpler.
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes and I did in my second post ask if there was a simpler way to do it
 
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

yes and I did in my second post ask if there was a simpler way to do it



And I really don't think that there is. The simplest way to swap content in a Swing application is to use a CardLayout. The tutorial for this is quite good, and if you want to give it a go, then by all means try. If your attempt fails, then post it here with your question. If you feel that you even this attempt is too complex, then what I meant by my post above is that perhaps you will need to change what you want your program to do, to behave in a simpler fashion, not to code this swapping in a simpler way. Best of luck
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a classmate that attend the class you missed that might be able to provide you with notes? Or at least can give you a better general idea of what your teacher discussed?

Can't you contact the teacher? Most teacher's today do provide their e-mail addresses. (Or is this not a college class?)

If we at least had a good starting point to know what concepts or topics where discussed, we might be able to help better. If you have only been programming for two weeks, then I would agree that the CardLayout is a bit advanced for where you are likely at in your studies. At the same time, I cannot see a teacher discussing the topic that it sounds like you are describing in the second or third week of a course. And the topic/example you mentioned in your original post sounds like a classic example for discussing the CardLayout class. So we all may misunderstanding the problem/topic you are asking for guidance on.

What have you learned so far? That might also help us determine a starting point to help you.
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is a high school class, and yea I'll go try to contact a class mate, thanks for the help
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With JButton there is one other way. Instead of swapping buttons, have one JButton and swap the Actions for it using setAction. The button will reflect the settings of the Action such as the name, icon, mnemonic, accelerator etc.
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well I got some help from a classmate I used an absolute layout on the holder they were in and had it set so when I click one it disappears and the next one appears
 
Rob Spoor
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No offense, but a) using absolute layouts is horrible, and b) that hiding and showing is just what CardLayout does for you.

In short, you create one JPanel with a CardLayout. You add all the buttons to that JPanel. You then use the CardLayout's next method to hide the current button and show the next.
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We usually discuss such things on a different forum. Moving.
 
David Crane
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob I really don't care, I just started programming and it's what was taught in the day of class I missed
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> ..so be quiet please

that will no doubt impress all those trying to help you.

what response do you expect you'll get for your next problem?

*plonk*
 
Rob Spoor
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. http://faq.javaranch.com/java/BeNice
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic