Forums Register Login

How to refresh Jframe with existing components

+Pie Number of slices to send: Send

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Read about card layout in the Java™ Tutorials.
+Pie Number of slices to send: Send

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send

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?
+Pie Number of slices to send: Send
 

Am I right?

Have you tried it?  What happened?
+Pie Number of slices to send: Send
 

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

Did it look like what you want?
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1222 times.
Similar Threads
JRadio
unable to insert JRadio in JTable.
JRadio Btn
JRadio Button : Event Listener
How values of a radio button selected can be retained
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:01:54.