1

I would like to create a close button. For this, I need a close icon, which I would like to get from the current UI style. I've found a function for this: UIManager.getIcon(key)

The only problem is, that I don't know any key. I have no idea, how to get a close icon.

Iter Ator
  • 8,226
  • 20
  • 73
  • 164

3 Answers3

5

Here is an exhausting list of keys:

http://thebadprogrammer.com/swing-uimanager-keys/

What you're looking for is "InternalFrame.closeIcon".

Also here is the list included along with official (Oracle) links to the resource keys:

https://stackoverflow.com/a/25740576/1705598

Community
  • 1
  • 1
icza
  • 389,944
  • 63
  • 907
  • 827
1

Use this snippet (is actually a fully functional class) to print all the UIManager key, or to filter them based on a keyword. In your case you want to check all the keys containing (ignore case for more results) a "close" string.

import java.util.Enumeration;
import javax.swing.UIManager;

public class Test {

  public static void main(String[] args) {
    printUIManagerKeys("close");
  }

  private static void printUIManagerKeys(String filter) {

    String filterToLowerCase = filter.toLowerCase();

    Enumeration<?> keys = UIManager.getDefaults().keys();

    while (keys.hasMoreElements()) {

      Object key = keys.nextElement();
      String keyToString = key.toString().toLowerCase();

      if (filter != null && keyToString.contains(filterToLowerCase)) {
        System.out.println(key + " ( " + UIManager.getDefaults().get(key) + " )");
      }
    }
  }
}

Output on the console:

InternalFrameTitlePane.closeButtonOpacity ( true )
PopupMenu.consumeEventOnClose ( false )
InternalFrame.paletteCloseIcon ( javax.swing.plaf.metal.OceanTheme$IFIcon@1fcb1a )
InternalFrame.closeSound ( sounds/FrameClose.wav )
InternalFrame.closeIcon ( javax.swing.plaf.metal.OceanTheme$IFIcon@100d6ea )
Tree.closedIcon ( sun.swing.ImageIconUIResource@1cc678a )

So next step is to get and see how the icon with the key InternalFrame.closeIcon looks.

Cristian Sulea
  • 274
  • 1
  • 6
1

The only problem is, that I don't know any key

Check out UIManager Defaults for code that displays all the UI properties in a GUI. The GUI displays the actual Icon so you can easily choose the Icon you want to use.

camickr
  • 321,443
  • 19
  • 166
  • 288