4

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

Jason Rogers
  • 19,194
  • 27
  • 79
  • 112
  • So, all you want to do is add a button to the top-right corner of a panel? – mre Jun 22 '11 at 00:03
  • 1
    Solution: use the right combination of layout managers. What have you tried so far? – Hovercraft Full Of Eels Jun 22 '11 at 00:05
  • This [link](http://stackoverflow.com/questions/5850949/how-to-place-jlabel-on-top-right-corner-just-below-the-title-bar) may help. Note: the accepted answer is a bit of a hack; as @Hovercraft Full Of Eels suggested, the correct solution involves using a layout manager correctly. – mre Jun 22 '11 at 00:16
  • sorry if I'm not clear I'll add a screen shot to try and make it clearer. @Havercraft Full Of Eels I haven't tried anything other than adding a text button to the panel as a temporary solution to continue working. – Jason Rogers Jun 22 '11 at 00:45
  • See also [Titled Borders for Panels](http://java.sun.com/products/jlf/ed1/dg/higg.htm#68818). – trashgod Jun 22 '11 at 01:42

2 Answers2

2

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.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
0

Because you are working with a container, you can add a button and arrange it with a layout manager. Does it have to overlap the border?

Travis G.
  • 218
  • 2
  • 9