• 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

Problem with the JButton.

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1- i have 2 buttons, i want to add them to the same location, when i click on button1 then the button1 will hidden and show button2, when i click on button2 then
button2 will hidden and show button1 again? please help me to slove my problem.
2- I have one button, but in this button i want to add 2 images (image1 and image2), when start the program, it's will show default button with image1, i want to
when i click on this button then image1 will hidden and show image2 on the button, when i click obn this button again so image2 will hidden and image1 show again.\
thanks for you help
 
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


1- i have 2 buttons, i want to add them to the same location, when i click on button1 then the button1 will hidden and show button2, when i click on button2 then
button2 will hidden and show button1 again? please help me to slove my problem.
2- I have one button, but in this button i want to add 2 images (image1 and image2), when start the program, it's will show default button with image1, i want to
when i click on this button then image1 will hidden and show image2 on the button, when i click obn this button again so image2 will hidden and image1 show again.\
thanks for you help



1) Why do you want to do that? What effect/functionality are you trying to achieve ?It is bad usability to show/hide/flip components on an existing UI. Are you aware, you can change the Icon/Text of a button any time?

2)Same as above. You can change the Icon of the button. Check out AbstractButton#setIcon(Icon icon) and AbstractButton#setSelectedIcon(Icon icon). You can subclass the JButton and maintain the state and flip icons accordingly. Also, if you want your button to "stay pressed/toggled" check out JToggleButtton.
[ October 05, 2008: Message edited by: Maneesh Godbole ]
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you very much.
That's my requrement, i have to finish it.
When i click on button 1, i will show panel1 and draw the chart in panel1 whith bar chart.
When i click on button 2, i will show panel2 and draw the chart in panel2 with line chart.
Button1 and button2 must the same location or only one button but deference image.
thanks for your help
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear all
i have new problem, i want to show the corresponding panel when i click on the button.(when i click on button with BART.jpg image it's will show panel1, when i click on button with LINE.jpg image it's will show panel2)I already create a flag, but it's not work.
Here is my source code:

please help me, thanks you very much
[ October 06, 2008: Message edited by: Tran Tuan Hung ]
 
Maneesh Godbole
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


Try calling revalidate() and repaint() after you set the panels.
Also take a look at the CardLayout. It does exactly what you want to do without you needing to code much.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i try this:

But it's not work, i already find the method revalidate() but i was not found.
I will research CardLayout follow your suggestion.
 
Maneesh Godbole
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
Sorry. I should have done this before I posted initially.

I ran your original code. Works for me just fine.
Most probably you are clicking on the button titled "BUTTON ON PANEL 1" on the NORTH which is NOT the button with the registered listener.
Try clicking on the button at the center (with the icon).

I still strongly urge you to try out the CardLayout.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you for reply,
OK, i already research on CardLayout, anhd i code it follow, but it still not works, please help me to correct it.
Here is my source code:
 
Maneesh Godbole
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

Originally posted by Tran Tuan Hung:
[QB].. but it still not works, please help me to correct it.



What exactly do you mean when you say it doesn't work?
Have you looked at this:
http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already successed, thanks you very much.
 
Maneesh Godbole
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

Originally posted by Tran Tuan Hung:
I already successed, thanks you very much.



Care to share your solution so others can benefit from it in the future?
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK You are the man,
I'll keep this solution for helping others. I think CardLayout that's userfull, interesting, but perhaps there're few persion know that.
 
Maneesh Godbole
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
I think you misunderstood.
I was requesting you to post your code snippet that works (like you have done previously), so that, in future, if anyone wants to solve a similar problem, they can refer to your code.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, OK and sorry for my misunderstood.
I post it now, hihi
Here is my source code, please comment for me hihi, i modify from your links.

[ October 07, 2008: Message edited by: Tran Tuan Hung ]
 
rubbery bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic