Java Reference
In-Depth Information
Figure 7-14. Title positioning
Because a TitledBorder contains another Border , you can combine more than one border
to place multiple titles along a single border. For example, Figure 7-15 shows a title along the
top and bottom of the border.
Figure 7-15. Showing multiple titles on a TitledBorder
The program used to generate Figure 7-15 is shown in Listing 7-2.
Listing 7-2. Multiple Titles on a TitledBorder
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class DoubleTitle {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("Double Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TitledBorder topBorder = BorderFactory.createTitledBorder("Top");
topBorder.setTitlePosition(TitledBorder.TOP);
TitledBorder doubleBorder = new TitledBorder(topBorder, "Bottom",
TitledBorder.RIGHT, TitledBorder.BOTTOM);
JButton doubleButton = new JButton();
doubleButton.setBorder(doubleBorder);
frame.add(doubleButton, BorderLayout.CENTER);
Search WWH ::




Custom Search