card.next(yourPanel); will go through all the components of your mainpanel , and then go to the first. To show the component with your own desire, try to follow (think if there are 5 components, and you are on 2 and want to show first, then you need to go through the rest of everything using the example of Vincent Ramdhani, the JRL answer is good in accordance with this gives a quick transition to the one you want, but here is another way.
import javax.swing.JLabel; import javax.swing.JPanel; public class myJFrame extends javax.swing.JFrame { private JPanel panel1, panel2; public myJFrame() { initComponents(); panel1=new JPanel(); panel2=new JPanel(); JLabel lb1=new JLabel("This is panel 1"); JLabel lb2=new JLabel("This is panel 2"); panel1.add(lb1); panel2.add(lb2);
This method is used when you have a tree and a panel or component is displayed in the tree. It directly shows this component. On the tree, add a value change listener and get the selection item and show the corresponding panel.
a question
source share