4

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?

partlov
  • 13,789
  • 6
  • 63
  • 82
adesh singh
  • 1,727
  • 9
  • 38
  • 70

3 Answers3

3

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

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
2

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.

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045