0

How can i display a tick mark like this -

enter image description here

and some text on a JButton.

   -----------------------
  |  mybutton [tick-mark] |
   -----------------------

Is there any way i can achieve this apart from placing an image on the button ?

Ankit Rustagi
  • 5,539
  • 12
  • 39
  • 70

2 Answers2

4

Use ImageIcon for button with tick image :

JButton b = new JButton();
b.setIcon(new ImageIcon("PATH_TO_ICON"));
b.setText("TEXT");
Maroun
  • 94,125
  • 30
  • 188
  • 241
alex2410
  • 10,904
  • 3
  • 25
  • 41
  • ImageIO.read is generally a more preferred method for reason an image, at least it will throw an Exception if the image can't be read. You might also consider mentioning embedded resources and the different methods involved in retrieving them ;) – MadProgrammer Nov 05 '13 at 07:37
3

You could try using one of the Unicode code-points that denote a "check mark". The alternatives are listed here.

If you take this approach, your buttons may look different (or even completely wrong) on different platforms due to font issues. An image is more likely to give a consistent "look".

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks, i was looking for a way to display unicode characters. But yes an image on the button should be better. – Ankit Rustagi Nov 05 '13 at 09:18
  • @AnkitRustagi: Definitely check target platforms, but the default font family used in the UI delegate is usually reasonable; a related `JToggleButton` example is seen [here](http://stackoverflow.com/a/7137801/230513). – trashgod Nov 05 '13 at 17:39