I have a question regarding the usage of actionListener for the title of a 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?
A titled border really isn't designed for this; it's a Border
, not a Component
. If the title is a user preference, the you can add it to your Preferences
dialog.
The authors of setBorder()
"recommend that you put the component in a JPanel
and set the border on the JPanel
." You could add a MouseAdapter
to that JPanel
and have the chosen handler bring up the Preferences
dialog, as @Catalina Island suggests.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.