我试过getTitlePosition,但它似乎只返回边框的起点0,而不是标题本身。我也尝试了 getBorderJustification,但它返回了 Center 的 int 值。
有没有办法在 TitledBorder 中获取实际文本的 x 位置?
Box container = Box.createVerticalBox();
Box topBox = new Box(BoxLayout.PAGE_AXIS);
Box btmBox = new Box(BoxLayout.PAGE_AXIS);
TitledBorder border = new TitledBorder("Title");
border.setTitleJustification(TitledBorder.CENTER);
topBox.add(new JLabel(new ImageIcon(new BufferedImage(200,40,BufferedImage.TYPE_INT_RGB))));
btmBox.add(new JLabel(new ImageIcon(new BufferedImage(200,40,BufferedImage.TYPE_INT_RGB))));
topBox.setBorder(border);
btmBox.setBorder(border);
container.add(topBox);
container.add(btmBox);