Wednesday, August 28, 2013

Create Dynamic components in JAVA


  1. First create a Swing container to hold dynamically generating objects.
  2. Then set a layout for the container
·            dynPanel.setLayout(new FlowLayout());
  1. Then create objects from components that you want to generate. 
·            JLabel lbl = new JLabel();
·            JTextField txt = new JTextField(12);
           4.       Then modify those objects as you want.
·            lbl.setText(allName);
·            txt.setText(String.valueOf(allValue + "0"));
·            txt.setEditable(false);

           5.      Then add those objects to the panel.
·            dynPanel.add(lbl);
·            dynPanel.add(txt);
           6.      Then repaint the container
·            dynPanel.revalidate();
·            validate();

No comments:

Post a Comment