[英]How do I apply an actionListener to the title of a TitledBorder?
I have a question regarding the usage of actionListener for the title of a TitledBorder: 我有一个关于actionListener用于TitledBorder标题的问题:
borderPanel1 = BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
MainFrame.windowTitle);
My final goal is to be able to press the title of the border to change the title of a panel. 我的最终目标是能够按边框标题来更改面板的标题。 How would I be able to add some kind of Listener to the title of this border?
我怎样才能在这个边框的标题上添加某种Listener?
A titled border really isn't designed for this; 标题边界确实不是为此而设计的; it's a
Border
, not a Component
. 它是
Border
,而不是Component
。 If the title is a user preference, the you can add it to your Preferences
dialog. 如果标题是用户首选项,则可以将其添加到
Preferences
对话框中。
The authors of setBorder()
"recommend that you put the component in a JPanel
and set the border on the JPanel
." 的作者
setBorder()
“建议你把组件在JPanel
,并设置边框的JPanel
。” You could add a MouseAdapter
to that JPanel
and have the chosen handler bring up the Preferences
dialog, as @Catalina Island suggests. 您可以将一个
MouseAdapter
添加到该JPanel
并让所选的处理程序调出Preferences
对话框,正如@Catalina Island建议的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.