import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FindDialog4 extends KDialog { JLabel findLabel = new JLabel("Find:"); JTextField findText = new JTextField(); 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 FindDialog4(new Frame(), "Find Dialog 4", true); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); dialog.setVisible(true); System.exit(0); } public FindDialog4(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(); 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)); // Space between text and check boxes box.add(createCheckRadioBox()); box.add(createVerticalStrut(17)); // Space between check boxes and action buttons box.add(createActionButtonBox()); return box; } private Box createFindTextBox() { Box box = Box.createHorizontalBox(); box.add(findLabel); box.add(createHorizontalStrut(11)); // Space between label and text box.add(findText); return box; } private Box createCheckRadioBox() { Box box = Box.createHorizontalBox(); Dimension lblSize; lblSize = findLabel.getPreferredSize(); // Space to align check boxes with text box.add(createHorizontalStrut(lblSize.width + 11)); box.add(createCheckButtonBox()); box.add(createRadioButtonBox()); 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(); box.add(findButton); box.add(createHorizontalStrut(5)); // Space between buttons box.add(closeButton); return box; } }