How do you go from this
JLabel
, a JMenuBar
) is a displayed
entity.
JPanel
, A JFrame
) holds zero or more
components.
upper-left corner, height and widthto each component in the container.
JLabel nameLabel = new JLabel("Name:") add(nameLabel) nameLabel.setBounds(x1, y1, w1, h1)
|
|
|
|
BorderLayout
divides its associated container into five areas.
|
BorderLayout.NORTH BorderLayout.SOUTH BorderLayout.EAST BorderLayout.WEST BorderLayout.CENTER
|
JFrame
s.
JContainer.setLayout(new BorderLayout())
1. The maximum dimensionsgetMaximumSize()
,2. the minimum dimensions
getMinimumSize()
,3. the prefered dimensions
getPreferredSize()
, and4. the current dimensions
getSize()
.
FlowLayout
does
word-processing-style layout:
JPanel
s.
|
|
be laid out?
|
JPanel io = new JPanel() io.add(new JButton("erase")) io.add(new JButton("read")) io.add(new JButton("write")) add(io, BorderLayout.SOUTH) add(new JTextArea())
|
|
ButtonGroup buttonGroup = new ButtonGroup(); JPanel appearence = new JPanel(); JRadioButton radioButton = new JRadioButton("normal", false); buttonGroup.add(radioButton); appearence.add(radioButton); radioButton = new JRadioButton("italic", false); buttonGroup.add(radioButton); appearence.add(radioButton); radioButton = new JRadioButton("bold", true); buttonGroup.add(radioButton); appearence.add(radioButton); add(appearence, BorderLayout.EAST);
|
|
appearence.setLayout(new BorderLayout()) JRadioButton radioButton = new JRadioButton("normal", false) buttonGroup.add(radioButton) appearence.add(radioButton, BorderLayout.NORTH) radioButton = new JRadioButton("italic", false) buttonGroup.add(radioButton) appearence.add(radioButton, BorderLayout.CENTER) radioButton = new JRadioButton("bold", true) buttonGroup.add(radioButton) appearence.add(radioButton, BorderLayout.SOUTH)
|
Grid
generalizes
border layout.
|
appearence.setLayout(new GridLayout(3, 1)) JRadioButton radioButton = new JRadioButton("normal", false) buttonGroup.add(radioButton) appearence.add(radioButton) radioButton = new JRadioButton("italic", false) buttonGroup.add(radioButton) appearence.add(radioButton) radioButton = new JRadioButton("bold", true) buttonGroup.add(radioButton) appearence.add(radioButton)
|
Box
lays out
components horizontally or vertically.
|
Box vbox = Box.createVerticalBox() vbox.add(radioButton) radioButton = new JRadioButton("italic", false) buttonGroup.add(radioButton) vbox.add(radioButton) radioButton = new JRadioButton("bold", true) buttonGroup.add(radioButton) vbox.add(radioButton) vbox.add(Box.createGlue()) panel.add(vbox)
|