Martin
Martin

Reputation: 202

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:

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?

Upvotes: 1

Views: 387

Answers (2)

trashgod
trashgod

Reputation: 205785

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.

Upvotes: 2

Catalina Island
Catalina Island

Reputation: 7126

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.

Upvotes: 2

Related Questions