簡體   English   中英

如何在TitledBorder中找到標題的x位置

[英]How to find the x position of the title in TitledBorder

我已經嘗試過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);

如果標題居中,我不知道如何確保彈出窗口保持在標題上方

因此,您需要檢查標題位置。 如果居中,則使用基本數學:

  1. 你知道面板的寬度
  2. 你知道彈出窗口的寬度
  3. 從面板寬度中減去彈出窗口寬度,然后除以2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM