简体   繁体   English

Java秋千关闭图标

[英]Java swing close icon

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. 为此,我需要一个close图标,我想从当前的UI样式中获取该图标。 I've found a function for this: UIManager.getIcon(key) 我为此找到了一个函数: UIManager.getIcon(key)

The only problem is, that I don't know any key. 唯一的问题是,我不知道任何键。 I have no idea, how to get a close icon. 我不知道如何获得close图标。

Here is an exhausting list of keys: 这是按键的详尽清单:

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

What you're looking for is "InternalFrame.closeIcon" . 您正在寻找的是"InternalFrame.closeIcon"

Also here is the list included along with official (Oracle) links to the resource keys: 另外,这里还包括列表以及指向资源密钥的官方(Oracle)链接:

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

Use this snippet (is actually a fully functional class) to print all the UIManager key, or to filter them based on a keyword. 使用此代码段(实际上是功能齐全的类)来打印所有UIManager键,或根据关键字对其进行过滤。 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 ) InternalFrameTitlePane.closeButtonOpacity(true)
PopupMenu.consumeEventOnClose ( false ) PopupMenu.consumeEventOnClose(false)
InternalFrame.paletteCloseIcon ( javax.swing.plaf.metal.OceanTheme$IFIcon@1fcb1a ) InternalFrame.paletteCloseIcon(javax.swing.plaf.metal.OceanTheme$IFIcon@1fcb1a)
InternalFrame.closeSound ( sounds/FrameClose.wav ) InternalFrame.closeSound(sounds / FrameClose.wav)
InternalFrame.closeIcon ( javax.swing.plaf.metal.OceanTheme$IFIcon@100d6ea ) InternalFrame.closeIcon(javax.swing.plaf.metal.OceanTheme$IFIcon@100d6ea)
Tree.closedIcon ( sun.swing.ImageIconUIResource@1cc678a ) Tree.closedIcon(sun.swing.ImageIconUIResource@1cc678a)

So next step is to get and see how the icon with the key InternalFrame.closeIcon looks. 因此,下一步是获取并查看带有键InternalFrame.closeIcon的图标的外观。

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. UIManager Defaults以获取在GUI中显示所有UI属性的代码。 The GUI displays the actual Icon so you can easily choose the Icon you want to use. GUI会显示实际的图标,因此您可以轻松选择要使用的图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM