• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to refresh Jframe with existing components

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello I want to have One JLabel (For question from database), four  JRadio Buttons for answer and options(from database) and Next button. I am using One Jrame which contains one JPanel. In my Jpanel I have loaded these components but how can I refresh/reload the panel with other these similar components when user click Next button for next question so that  label should be loaded with another question and radio buttons with other answer/options.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a sequence of panels of components to be shown to the user you could use the java.awt.CardLayout layout manager to allow you to easily 'flip' panels.
 
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

label should be loaded with another question and radio buttons with other answer/options.  


Those components have methods to set their text.  Have you tried using them?
 
javedkhan khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some one told me that if you have same components to display each time, like every question contains same label, radiobuttons, and button, you do not need card layout. Can you please guide me how can I use card layout? I mean I will have one panel with card layout and these components, what will I do when user click Next button. How to shuffle the cards, how many panels I will have, it will be great if you come up with a brief detail.
Thanks
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if the components are the same for each panel then you can just change the text displayed by each component. But if you have different components on the panels then you will need to use another approach such as CardLayout. For help on using this layout manager see the Java tutorial https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
 
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read about card layout in the Java™ Tutorials.
 
javedkhan khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks again.
Actually coming specific to my project, suppose I want to include questions like true/false having different components (JLabel/Two radio buttons and Next button), then I will have separate panel for it? And if I want to include another type of question in which user will directly input answer to text field(no choices/radio buttons), I will have separate jPanel for it, right?
In this case, I will have three jPanels? In which Panel I will have to set the layout as Card layout?
Second, these three panels will be separate in one jframe or one main panel will contain these three jpanels?

Very thankful for your time.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. You should not go round thinking what sort of components you will need. You start by asking what you want the display to look like. Draw it with true‑false questions included and that drawing shou‍ld tell you what components you will need.
 
javedkhan khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I know which components to add for each type of questions, but I want to ask, suppose I have three different types of questions with three different types of components, so it means I will have three jpanels one for each type of question? And besides these three separate jpanels,  one main panel  which contain these three panels? And the cardlayout will be set for main Jpanel,?
Am I right?
 
Norm Radder
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Am I right?

Have you tried it?  What happened?
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:. . . Have you tried it?  What happened?

Did it look like what you want?
 
Hold that thought. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic