Search code examples
javaswingjpaneljbuttontitled-border

Java Swing: adding button to TitledBorder


I have a list of TitledBorder panels that contain textfields that represents point.

I've just been asked to add a button to the panel with the TitledBorder, that will alow me delete the panel and its contents.

so how can I add a button in the top right corner of a panel with TitledBorder?


edit here is what I have

enter image description here

and here is what I would like to add (sorry this no professional photoshop quality :P)

enter image description here


Solution

  • Start from the example http://www.java2s.com/Code/Java/Swing-JFC/CustomBorderSample.htm

    You can draw whatever you want on the border. Also just add MouseListener to you componnet and check Point of the MouseEvent. If the click happens in the image area do your code there.