adesh singh
adesh singh

Reputation: 1727

Draw something on JButton's right and top corner

I am trying to create JButton such as there must be a number painted on the top and right corner of JButton.

For example, in case of notification buttons there is a message in the button, how is that possible? Can the help be taken of paint method to draw the label?

Upvotes: 4

Views: 301

Answers (3)

trashgod
trashgod

Reputation: 205775

Also consider implementing Icon to decorate the button; ColorIcon is a simple example. You can use the color to signify buttons that are likely to need attention, and you can use drawString() specify a number.

Upvotes: 1

Denis Tulskiy
Denis Tulskiy

Reputation: 19167

JButton and any JComponent extend Container class, so you should be able to add elements into JButton as if it were a simple panel. So in your case you can add a JLabel with your text into a button.

Upvotes: 2

mKorbel
mKorbel

Reputation: 109815

there are three ways, by using

  1. GlassPane

  2. JLayer (Java7) based on JXLayer(Java6)

  3. JButtton (all JComponents) is container too, there is easy and possible use standard LayoutManagers (only JFrame == BorderLayout and JPanel == FlowLayout have got implemented LayoutManager in API directly), then basically everything is possible

Upvotes: 3

Related Questions