Delta Charlie Delta Charlie - 1 year ago 57
Java Question

How to change border title on button click?

I am trying to build a GUI interface. I have made wrapper panel which has the title "Staff Details" as in the screenshot below:

output

I used the following code to set the title on the border

wrapper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Staff Details",TitledBorder.CENTER, TitledBorder.TOP));


Now I want to change the title to "View Details" when I click the "View" button. How do I do that?

Answer Source

Probably keep the TitledBorder reference

TitledBorder titledBorder = BorderFactory.createTitledBorder(...);

Then you should be able to just setTitle()

titledBorder.setTitle("New Title");
repaint();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download