[英]How do I apply an actionListener to the title of a TitledBorder?
[英]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);
如果標題居中,我不知道如何確保彈出窗口保持在標題上方
因此,您需要檢查標題位置。 如果居中,則使用基本數學:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.