This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make custom components ?  RSS feed

 
Christophe Monnet
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm trying to build my own swing component.
I would like to make a component like JLabel (text display - no edit) but with any shape around the label: circle, triangle, diamond...
Should I start from JLabel? JComponent? Higher class?
I've looked into JLabel code and it seems pretty tricky. I've made components in C++ but the swing paradigm is totally different I guess.
What is this LabelUI class ?
I was wondering if anyone had web ressource to share on the subject of building swing components ?

Thanks in advance,
Chris
 
Wilfried LAURENT
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello
I'm trying to build my own swing component.

Hard work!

Should I start from JLabel? JComponent? Higher class?

If you try to implement your own graphical toolkit, my advise is to have a super-component, from which all your components will inherit. It would contain method like setBackground etc ...

I've looked into JLabel code and it seems pretty tricky.

I confirm your impression. But if you dive into it, it is possible to get the point quite quickly.


What is this LabelUI class ?

In Swing, each component has a UI delegate : JLabel has his LabelUI, JList his ListUI etc.... This UI delegate are classes to which the J-Component delegates some of its tasks, and particularly the tasks related to the look-and-feel.
If fact the UI delegates are interfaces, which are implemented by classes specific to a look-and-feel : That is the MetalLabelUI in the javax.swing.plaf.metal package.
All the delegation process is hidden. It is the UIManager task to install a specific look-and-feel and to ensure the integrity.
The best on-line resource I found can be reached at: http://ccfit.nsu.ru/programming/java/books/JFCUnleashed/index.htm
Chapter 23, 24 and 30.
W.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a link on round buttons You should be able to take that example and apply it to JLabel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!