import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FindDialog5 extends KDialog { JLabel findLabel = new JLabel("Find:"); JTextField findText = new JTextField(20); // set minimum width JCheckBox caseCheck = new JCheckBox("Match Case"); JCheckBox wordCheck = new JCheckBox("Whole Word"); JRadioButton topRadio = new JRadioButton("Start at Top"); JRadioButton wrapRadio = new JRadioButton("Wrap Around"); JButton findButton = new JButton("Find"); JButton closeButton = new JButton("Close"); public static void main(String[] args) { JDialog dialog = new FindDialog5(new Frame(), "Find Dialog 5", true); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); dialog.setVisible(true); System.exit(0); } public FindDialog5(Frame owner, String title, boolean modal) { super(owner, title, modal); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { setVisible(false); } }); layoutComponents(); pack(); setLocationRelativeTo(owner); } private void layoutComponents() { Container content = getContentPane(); shrinkWrap(new AbstractButton[] { caseCheck, wordCheck, // shrink wrap check boxes and radio buttons topRadio, wrapRadio }); content.add(createVerticalStrut(13), BorderLayout.NORTH); content.add(createVerticalStrut(10), BorderLayout.SOUTH); content.add(createHorizontalStrut(11), BorderLayout.WEST); content.add(createHorizontalStrut(10), BorderLayout.EAST); content.add(createMainBox()); } private Box createMainBox() { Box box = Box.createVerticalBox(); box.add(createFindTextBox()); box.add(createVerticalStrut(11)); box.add(createCheckRadioBox()); box.add(createVerticalStrut(17)); box.add(createActionButtonBox()); return box; } private Box createFindTextBox() { Box box = Box.createHorizontalBox(); box.add(findLabel); box.add(createHorizontalStrut(11)); box.add(findText); return box; } private Box createCheckRadioBox() { Box box = Box.createHorizontalBox(); Dimension lblSize; lblSize = findLabel.getPreferredSize(); box.add(createHorizontalStrut(lblSize.width + 11)); box.add(createCheckButtonBox()); box.add(createRadioButtonBox()); box.add(Box.createHorizontalGlue()); return box; } private Box createCheckButtonBox() { Box box = Box.createVerticalBox(); box.add(caseCheck); box.add(wordCheck); return box; } private Box createRadioButtonBox() { Box box = Box.createVerticalBox(); box.add(topRadio); box.add(wrapRadio); return box; } private Box createActionButtonBox() { Box box = Box.createHorizontalBox(); matchComponentSize(new JComponent[] // Make buttons the same size { findButton, closeButton }); box.add(Box.createHorizontalGlue()); // Push buttons to right box.add(findButton); box.add(createHorizontalStrut(5)); box.add(closeButton); return box; } }