Chapter 13 fig 13-4 JLabel mylabel = new JLabel(String) JLabel mylabel = new JLabel(String, Icon, position of icon) positions: SwingConstants.LEFT .RIGHT .CENTER .TOP .BOTTOM .CENTER mylabel.setText(String) mylabel.setIcon(Icon) mylabel.setToolTip(String) mylabel.setHorizontalAlignment(position) fig 13-7 JTextField mytext = new JTextField(int size) JTextField mytext = new JTextField(String, int size) mytext.setEditable(boolean) //default true JPasswordField mypass = new JPasswordField(int size) fig 13-10 JButton mybutton = new JButton(String) JButton mybutton = new JButton(String, Icon) mybutton.setVisible(boolean) mybutton.setRolloverIcon(Icon) fig 13-11 JCheckBox mycheck = new JCheckBox(String) mycheck.isSelected() //returns boolean mycheck.addItemListener(object that implements ItemListener) fig 13-12 JRadioButton myradio1 = new JRadioButton(String, boolean selected) myradio1.addItemListener(object that implements ItemListener) ButtonGroup myradios = new ButtonGroup() //not added to a Container myradios.add(myradio1) fig 13-13 JComboBox mycombo = new JComboBox(String[]) mycombo.setMaximumRowCount(int rows) mycombo.getSelectedIndex() mycombo.addItemListener(object that implements ItemListener) fig 13-14 JList mylist = new JList(String[]) mylist.setVisibleRowCount(int rows) mylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) mylist.setFixedCellWidth(int pixels_size) mylist.setFixedCellHeight(int pixels_size_item) mylist.getSelectedIndex() container.add(new JScrollPane(mylist)) //scroll bars not with JList mylist.addListSelectionListener(object that implements ListSelectionListener) mylist.setListData(String[]) mylist.getSelectedValues() //returns String[] *************************** Layout Managers Container container = getContentPane(); FlowLayout: left to right, top to bottom FlowLayout layout = new FlowLayout(); container.setLayout( layout ); OR container.setLayout( new FlowLayout() ); container.add( someGUIobject ); //in order added container.add( someGUIobject, 6 ); //in 6th position BorderLayout: 5 areas: NORTH SOUTH EAST WEST CENTER NORTH SOUTH thin & wide EAST WEST tall & narrow CENTER hogs don't have to use all 5 areas. others will expand into that unused area default for JApplet BorderLayout layout = new BorderLayout(); BorderLayout layout = new BorderLayout(4,4); //gaps between areas (1,1 is default) container.setLayout( layout ); OR container.setLayout( new BorderLayout() ); container.add( someGUIobject, BorderLayout.EAST); //etc. GridLayout: rows & columns table GridLayout layout = new GridLayout(4,3); //4 rows, 3 columns container.setLayout( layout ); OR container.setLayout( new GridLayout(4,3) ); container.add( someGUIobject ); //in order added //All the layout managers: //realign, re-layout if GUIs move, change, visible: layout.layoutContainer (getContentPane() ); OR container.validate(); Each area can have only one GUI object. But the GUI object can be a JPanel which is composed of GUI objects managed by a layout manager. JPanel myPanel = new JPanel(); myPanel.setLayout( new GridLayout(2,4)); //or other layout manager for this panel myPanel.add( someGUIobject ); ... container.add (myPanel); //in next position OR container.add (myPanel, BorderLayout.SOUTH); //etc Absolute positioning by not having a layout manager: container.setLayout( null ); Each GUI component must be positioned by its setBounds method: someGUIobject.setBounds( x1, y2, width, length );