我已经尝试过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);
答案 0 :(得分:2)
如果标题居中,我不知道如何确保弹出窗口保持在标题上方
因此,您需要检查标题位置。如果居中,则使用基本数学: