• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add a component on the Border of JPanel?

 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add a component (a RadioButton...) on TitleBorder of JPanel.
So i don't know how to do it.
Plesase help me to do it.
Thanks a lot.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A border is just that - a border. It shouldn't include other components (and it's not possible to do that with the borders that are part of Swing).

You could write your own border class that extends AbstractBorder, and in its paintBorder method you should be able to put any components you like.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you very much Ulf Dittmer.
But i didn't know how to use paintBorder to add a component on it.
Can you give me a small example to do it and i am sorry for my stupid.
although i have searched on google, but it not help me.
Thanks very much
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea how to go about it; as I said, I think it's not a good idea.

The fact that you didn't find anyone else doing it, either, should tell you something. There are most likely better ways to achieve what you're trying to do, possibly involving the use of layouts.
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tran Tuan Hung:
I want to add a component (a RadioButton...) on TitleBorder of JPanel.


This is how you can do it.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ulf Dittmer and Maneesh Godbole very much.
I am a noob, so that's hard with me.
One again, thanks very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic