Java Reference
In-Depth Information
this.add(new JLabel(" "), BorderLayout.WEST);
this.add(clientServerPanel, BorderLayout.CENTER);
pack();
}
}
Figure 8-18. Demonstration of the JComboBox component and the BorderFactory
Listing 8-7 was designed to show how to make a simple border without introducing too
many new features at once. To that end, we put empty labels around the border just to make it
stand out—normally you would not do this in practice. Instead, you might consider using a
compound border, as shown in Listing 8-8. This will produce an almost identical result to that
shown in Figure 8-18.
Listing 8-8. Demonstration of a Compound Border
import java.awt.*;
import javax.swing.*;
public class MyFrame extends JFrame {
private final static String TITLE = "Title goes here";
public static void main(String[] args) throws Exception {
new MyFrame().setVisible(true);
}
public MyFrame() throws Exception {
setDefaultCloseOperation(EXIT_ON_CLOSE);
String[] items = {"One", "Two", "Three", "Four", "Five"};
JComboBox choosableItems = new JComboBox(items);
JPanel clientServerPanel = new JPanel();
clientServerPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(10, 10, 10, 10),
BorderFactory.createTitledBorder(TITLE)));
Search WWH ::




Custom Search