Community
Participate
Working Groups
============== import javax.swing.Box; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; public class MyGUI extends JPanel { private Box box = null; private JLabel label = null; private JButton button = null; private JList list = null; private DefaultListModel model = null; /** * This method initializes * */ public MyGUI() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.add(getBox()); this.setSize(538, 247); } /** * Returns the box. * @return Box */ public Box getBox() { if (box==null) { box = Box.createHorizontalBox(); box.add(getLabel()); box.add(Box.createHorizontalStrut(15)); box.add(getButton()); box.add(Box.createHorizontalStrut(15)); box.add(getList()); } return box; } /** * Sets the box. * @param box The box to set */ public void setBox(Box box) { this.box = box; } /** * Returns the button. * @return JButton */ public JButton getButton() { if (button==null) { button=new JButton("OK"); } return button; } /** * Returns the label. * @return JLabel */ public JLabel getLabel() { if (label==null) { label = new JLabel("My label"); } return label; } /** * Sets the button. * @param button The button to set */ public void setButton(JButton button) { this.button = button; } /** * Sets the label. * @param label The label to set */ public void setLabel(JLabel label) { this.label = label; } /** * Returns the list. * @return JList */ public JList getList() { if (list==null) { list = new JList(); list.setSize(30, 42); list.setModel(getModel()); } return list; } /** * Sets the list. * @param list The list to set */ public void setList(JList list) { this.list = list; } /** * Returns the model. * @return DefaultListModel */ public DefaultListModel getModel() { if (model==null) { model = new DefaultListModel(); model.addElement("red"); model.addElement("yellow"); model.addElement("green"); } return model; } /** * Sets the model. * @param model The model to set */ public void setModel(DefaultListModel model) { this.model = model; } } // @jve:visual-info decl-index=0 visual-constraint="0,0"