package jalview.appletgui; import awt2swing.Frame; import java.awt.Graphics; import java.awt.Insets; import awt2swing.Label; import awt2swing.Panel; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class TitledPanel extends Panel { private String title; private Insets insets = new Insets(10, 10, 10, 10); public TitledPanel() { this(""); } public TitledPanel(String title) { this.setTitle(title); } public Insets getInsets() { return insets; } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(getForeground()); g.drawRect(5, 5, getWidth() - 10, getHeight() - 10); int width = g.getFontMetrics().stringWidth(getTitle()); g.setColor(getBackground()); g.fillRect(10, 0, width, 10); g.setColor(getForeground()); awt2swing.Util.drawString(g, getTitle(), 10, 10); } /** * @j2sIgnore * * @param args */ public static void main(String[] args) { Frame f = new Frame("TitledPanel Tester"); TitledPanel p = new TitledPanel("Title of Panel"); p.add(new Label("Label 1")); p.add(new Label("Label 2")); p.add(new Label("Label 3")); f.add(p); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setBounds(300, 300, 300, 300); f.setVisible(true); } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }