How can I work with a map layout in NetBeans GUI Builder?

Does anyone know how to work with a map layout in a NetBeans grid builder? I want to show the panels according to the choice of JRadioButton , so I want to expand it using the map layout.

+6
java swing netbeans cardlayout gui-editor
source share
3 answers

Here is a very simple tutorial that can get you started in the right direction. I hope this will be helpful.

+14
source share

The sun tutorial seems like a good place to start learning map layouts.

As for NetBeans as such, simply assign the map layout to the component you want to assign (for example, JPanel), give it a name, and then for JPanel child components (for example, other JPanels) specify their cardName property. To switch from one to another, you encode it in an event.

+3
source share

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; /** * Creates new form myJFrame */ 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); //make more if you want // contentPanel.add(panel1);//show any of the panel first } private void initComponents() { jPanel1 = new javax.swing.JPanel(); buttonPanel1 = new javax.swing.JButton(); buttonPanel2 = new javax.swing.JButton(); contentPanel = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); buttonPanel1.setText("Panel 1"); buttonPanel1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonPanel1ActionPerformed(evt); } }); buttonPanel2.setText("Panel 2"); buttonPanel2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonPanel2ActionPerformed(evt); } }); .... } private void buttonPanel2ActionPerformed(java.awt.event.ActionEvent evt) { contentPanel.removeAll(); contentPanel.add(panel2); contentPanel.repaint(); contentPanel.revalidate(); } private void buttonPanel1ActionPerformed(java.awt.event.ActionEvent evt) { contentPanel.removeAll(); contentPanel.add(panel1); contentPanel.repaint(); contentPanel.revalidate(); } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new myJFrame().setVisible(true); } }); } private javax.swing.JButton buttonPanel1; private javax.swing.JButton buttonPanel2; private javax.swing.JPanel contentPanel; private javax.swing.JPanel jPanel1; } 

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.

+1
source share

All Articles