Das einfachste was mir ad hoc einfällt geht so: [Highlight=Java]final Border border =
new TitledBorder(BorderFactory.createEtchedBorder(), "Text Search",
TitledBorder.LEADING, TitledBorder.TOP) {
private Insets insets = new Insets(0, 0, 0, 0);
@Override
public Insets getBorderInsets(Component c, Insets insets) {
final Insets i = super.getBorderInsets(c, insets);
final int space = EDGE_SPACING + TEXT_SPACING;
i.left -= space;
i.right -= space;
i.bottom -= space;
return i;
}
@Override
public void paintBorder(
Component c,
Graphics g,
int x,
int y,
int width,
int height) {
final Shape orgClip = g.getClip();
final int space = EDGE_SPACING + TEXT_SPACING;
getBorderInsets(c, insets);
try {
g.clipRect(x + space, y, width - 2 * space, insets.top);
super.paintBorder(c, g, x, y, width, height);
} finally {
g.setClip(orgClip);
}
}
};
final JPanel panel = new JPanel(new BorderLayout(6, 6));
panel.add(new JTextField(20), BorderLayout.CENTER);
panel.add(new JButton("Rumble"), BorderLayout.LINE_END);
panel.setBorder(border);
final JFrame f = new JFrame("Titled Border Fun");
f.getContentPane().add(panel);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setVisible(true);[/Highlight]
Sieht so aus:
Ist das wie gewünscht? Ggf. kannst Du den Border in Zeile 2 austauschen oder
null setzen. Spiel mal damit rum.
Ebenius