P
pek
Let's say you want to create a small game using Swing components
instead of overriding the paint method.. But you want the components
to look more graphical than the usual look and feel they have (without
of course creating a Look and Feel). What would you prefer in order to
draw a transparent icon that will react on mouse over and clicking on
it? Go ahead and run HouseOfCards in http://treazy.com/apps/javacorner
to see what do I mean. In the game, every button is a swing component,
a JLabel in particular.
With a JButton you can use the ActionListener to listen when the
button is clicked and MouseListener for mouse entered/exited for the
mouse over effect. But, you have to customize the borders so it would
look less of a component.
On the other hand, using JLabel is probably easier. You only need
to add a MouseListener where you would add code to the clicked,
entered and exited to perform the same thing with the button AND avoid
changing anything as opposed to JButton's border.
Assuming that in both cases you want the component's background to
be transparent (setOpaque(false)), is using a JLabel for buttons a bad
practice? Are there any performance issues or disadvantages?
instead of overriding the paint method.. But you want the components
to look more graphical than the usual look and feel they have (without
of course creating a Look and Feel). What would you prefer in order to
draw a transparent icon that will react on mouse over and clicking on
it? Go ahead and run HouseOfCards in http://treazy.com/apps/javacorner
to see what do I mean. In the game, every button is a swing component,
a JLabel in particular.
With a JButton you can use the ActionListener to listen when the
button is clicked and MouseListener for mouse entered/exited for the
mouse over effect. But, you have to customize the borders so it would
look less of a component.
On the other hand, using JLabel is probably easier. You only need
to add a MouseListener where you would add code to the clicked,
entered and exited to perform the same thing with the button AND avoid
changing anything as opposed to JButton's border.
Assuming that in both cases you want the component's background to
be transparent (setOpaque(false)), is using a JLabel for buttons a bad
practice? Are there any performance issues or disadvantages?