Java Code Examples for javax.swing.UIManager#getIcon()

The following examples show how to use javax.swing.UIManager#getIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSystemView.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Icon for a file, directory, or folder as it would be displayed in
 * a system file browser. Example from Windows: the "M:\" directory
 * displays a CD-ROM icon.
 *
 * The default implementation gets information from the ShellFolder class.
 *
 * @param f a <code>File</code> object
 * @return an icon as it would be displayed by a native file chooser
 * @see JFileChooser#getIcon
 * @since 1.4
 */
public Icon getSystemIcon(File f) {
    if (f == null) {
        return null;
    }

    ShellFolder sf;

    try {
        sf = getShellFolder(f);
    } catch (FileNotFoundException e) {
        return null;
    }

    Image img = sf.getIcon(false);

    if (img != null) {
        return new ImageIcon(img, sf.getFolderType());
    } else {
        return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
    }
}
 
Example 2
Source File: SwitchButtonUI.java    From pumpernickel with MIT License 6 votes vote down vote up
private void initializeUIManager() {
	for (String word : new String[] { "background", "border",
			"disabledText", "focusInputMap", "font", "foreground",
			"margin", "select", "textIconGap", "textShiftOffset" }) {
		String otherKey = "CheckBox." + word;
		String myKey = getPropertyPrefix() + word;
		if (UIManager.get(myKey) == null) {
			Object value = UIManager.get(otherKey);
			UIManager.put(myKey, value);
		}
	}

	String iconKey = getPropertyPrefix() + "icon";
	Icon icon = UIManager.getIcon(iconKey);
	if (icon == null) {
		if (JVM.isWindows) {
			icon = new WindowsSwitchButtonIcon();
		} else if (JVM.isMac) {
			icon = new AquaSwitchButtonIcon();
		} else {
			icon = new AquaSwitchButtonIcon();
		}
		UIManager.put(iconKey, icon);
	}
}
 
Example 3
Source File: FileChooserUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

	if (value == null) {
		setText("");
		return this;
	}
	File directory = (File) value;
	setText(getFileChooser().getName(directory));
	Icon icon = getFileChooser().getIcon(directory);
	if (icon == null) {
		icon = UIManager.getIcon("FileChooser.defaultDirectoryIcon");
	}

	this.indentIcon.icon = icon;
	this.indentIcon.depth = FileChooserUI.this.directoryComboBoxModel.getDepth(index);
	setIcon(this.indentIcon);

	if (isSelected && index > -1) {
		setBorder(FileChooserUI.this.roundComboboxListRendererBorder);
	}

	return this;
}
 
Example 4
Source File: BadgeIcons.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Image getTreeFolderIcon(boolean opened) {
  Image base = (Image) UIManager.get(opened ? OPENED_ICON_KEY_UIMANAGER_NB : ICON_KEY_UIMANAGER_NB); // #70263;
  if (base == null) {
    Icon baseIcon = UIManager.getIcon(opened ? OPENED_ICON_KEY_UIMANAGER : ICON_KEY_UIMANAGER); // #70263
    if (baseIcon != null) {
      base = ImageUtilities.icon2Image(baseIcon);
    }
    else { // fallback to our owns
      base = ImageUtilities.loadImage(opened ? OPENED_ICON_PATH : ICON_PATH, true);
    }
  }
  return base;
}
 
Example 5
Source File: ButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Button to scroll tabs right/down. The button sets up a timer when pressed
 * to call the scroll action repeatedly until released or until the action
 * becomes disabled.
 * @param scrollAction Action implementing the actual scrolling.
 * @return Button to scroll right/down.
 */
public static JButton createScrollRightButton( Action scrollAction ) {
    JButton btn = new TimerButton( scrollAction );
    Icon icon = UIManager.getIcon("nb.multitabs.button.right.icon");
    if (icon == null) {
        icon = ImageUtilities.loadImageIcon( "org/netbeans/core/multitabs/resources/right.png", true ); //NOI18N
    }
    btn.setIcon( icon );
    btn.setToolTipText( NbBundle.getMessage(ButtonFactory.class, "Hint_ScrollRight") );
    return btn;
}
 
Example 6
Source File: FileIconDemo.java    From pumpernickel with MIT License 5 votes vote down vote up
protected void refreshFile() {
	File file = new File(filePathField.getText());
	Icon icon;
	FileIcon fileIcon = getFileIcon();
	fileLabel.setText("");
	if (!file.exists()) {
		icon = new StrikeThroughIcon(Color.gray, 20);
		fileLabel.setText("File Missing");
	} else if (fileIcon != null) {
		icon = fileIcon.getIcon(file, false);
	} else {
		icon = UIManager.getIcon("FileView.fileIcon");
		fileLabel.setText("FileView.fileIcon");
	}
	int w = icon.getIconWidth();
	int h = icon.getIconHeight();
	if (sizeSlider.isEnabled()) {
		int m = sizeSlider.getValue();
		Dimension d = Dimension2D.scaleProportionally(new Dimension(w, h),
				new Dimension(m, m));
		if (d.width != w || d.height != h) {
			icon = IconUtils.createScaledIcon(icon, d.width, d.height);
			if (fileLabel.getText().length() == 0) {
				fileLabel.setText("Scaled");
			} else {
				fileLabel.setText(fileLabel.getText() + " - Scaled");
			}
		}
	} else if (!sizeSliderUsed) {
		sizeSlider.setValue(Math.max(w, h));
	}
	fileLabel.setIcon(icon);
}
 
Example 7
Source File: CloseButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Icon getBigCloseTabImage() {
    if( null == bigCloseTabImage ) {
        bigCloseTabImage = UIManager.getIcon("nb.bigclose.tab.icon.enabled.icon"); //NOI18N
    }
    if( null == bigCloseTabImage ) {
        String path = UIManager.getString("nb.bigclose.tab.icon.enabled.name" ); //NOI18N
        if( null != path ) {
            bigCloseTabImage = ImageUtilities.loadImageIcon(path, true); // NOI18N
        }
    }
    if( null == bigCloseTabImage ) {
        if( isWindows8LaF() || isWindows10LaF() ) {
            bigCloseTabImage = Windows8VectorCloseButton.DEFAULT;
        } else if( isWindowsVistaLaF() ) {
            bigCloseTabImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/vista_bigclose_enabled.png", true); // NOI18N
        } else if( isWindowsXPLaF() ) {
            bigCloseTabImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/xp_bigclose_enabled.png", true); // NOI18N
        } else if( isWindowsLaF() ) {
            bigCloseTabImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/win_bigclose_enabled.png", true); // NOI18N
        } else if( isAquaLaF() ) {
            bigCloseTabImage = AquaVectorCloseButton.DEFAULT;
        } else if( isGTKLaF() ) {
            bigCloseTabImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/gtk_bigclose_enabled.png", true); // NOI18N
        } else {
            bigCloseTabImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/metal_bigclose_enabled.png", true); // NOI18N
        }
    }
    return bigCloseTabImage;
}
 
Example 8
Source File: ToolbarContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Paint bumps to specific Graphics. */
@Override
public void paint (Graphics g) {
    Icon icon = UIManager.getIcon("ToolBar.handleIcon");
    Region region = Region.TOOL_BAR;
    SynthStyleFactory sf = SynthLookAndFeel.getStyleFactory();
    SynthStyle style = sf.getStyle(toolbar, region);
    SynthContext context = new SynthContext(toolbar, region, style, SynthConstants.DEFAULT);

    SynthGraphicsUtils sgu = context.getStyle().getGraphicsUtils(context);
    sgu.paintText(context, g, null, icon, SwingConstants.LEADING, SwingConstants.LEADING, 0, 0, 0, -1, 0);
}
 
Example 9
Source File: InternalFrameTitlePane.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void installDefaults() {
	super.installDefaults();
	this.rolloverCloseIcon = UIManager.getIcon("InternalFrame.rolloverCloseIcon");
	this.rolloverIconifyIcon = UIManager.getIcon("InternalFrame.rolloverIconifyIcon");
	this.rolloverMinimizeIcon = UIManager.getIcon("InternalFrame.rolloverMinimizeIcon");
	this.rolloverMaximumIcon = UIManager.getIcon("InternalFrame.rolloverMaximizeIcon");
}
 
Example 10
Source File: FlatTitlePane.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
protected JButton createButton( String iconKey, String accessibleName, ActionListener action ) {
	JButton button = new JButton( UIManager.getIcon( iconKey ) );
	button.setFocusable( false );
	button.setContentAreaFilled( false );
	button.setBorder( BorderFactory.createEmptyBorder() );
	button.putClientProperty( AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName );
	button.addActionListener( action );
	return button;
}
 
Example 11
Source File: CloseButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Icon getCloseTabRolloverImage() {
    if( null == closeTabMouseOverImage ) {
        closeTabMouseOverImage = UIManager.getIcon("nb.close.tab.icon.rollover.icon"); //NOI18N
    }
    if( null == closeTabMouseOverImage ) {
        String path = UIManager.getString("nb.close.tab.icon.rollover.name" ); //NOI18N
        if( null != path ) {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon(path, true); // NOI18N
        }
    }
    if( null == closeTabMouseOverImage ) {
        if( isWindows8LaF() || isWindows10LaF() ) {
            closeTabMouseOverImage = Windows8VectorCloseButton.PRESSED;
        } else if( isWindowsVistaLaF() ) {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/vista_close_rollover.png", true); // NOI18N
        } else if( isWindowsXPLaF() ) {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/xp_close_rollover.png", true); // NOI18N
        } else if( isWindowsLaF() ) {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/win_close_rollover.png", true); // NOI18N
        } else if( isAquaLaF() ) {
            closeTabMouseOverImage = AquaVectorCloseButton.ROLLOVER;
        } else if( isGTKLaF() ) {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/gtk_close_rollover.png", true); // NOI18N
        } else {
            closeTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/metal_close_rollover.png", true); // NOI18N
        }
    }
    return closeTabMouseOverImage;
}
 
Example 12
Source File: CloseButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Icon getBigCloseTabRolloverImage() {
    if( null == bigCloseTabMouseOverImage ) {
        bigCloseTabMouseOverImage = UIManager.getIcon("nb.bigclose.tab.icon.rollover.icon"); //NOI18N
    }
    if( null == bigCloseTabMouseOverImage ) {
        String path = UIManager.getString("nb.bigclose.tab.icon.rollover.name" ); //NOI18N
        if( null != path ) {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon(path, true); // NOI18N
        }
    }
    if( null == bigCloseTabMouseOverImage ) {
        if( isWindows8LaF() || isWindows10LaF() ) {
            bigCloseTabMouseOverImage = Windows8VectorCloseButton.PRESSED;
        } else if( isWindowsVistaLaF() ) {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/vista_bigclose_rollover.png", true); // NOI18N
        } else if( isWindowsXPLaF() ) {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/xp_bigclose_rollover.png", true); // NOI18N
        } else if( isWindowsLaF() ) {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/win_bigclose_rollover.png", true); // NOI18N
        } else if( isAquaLaF() ) {
            bigCloseTabMouseOverImage = AquaVectorCloseButton.ROLLOVER;
        } else if( isGTKLaF() ) {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/gtk_bigclose_rollover.png", true); // NOI18N
        } else {
            bigCloseTabMouseOverImage = ImageUtilities.loadImageIcon("org/openide/awt/resources/metal_bigclose_rollover.png", true); // NOI18N
        }
    }
    return bigCloseTabMouseOverImage;
}
 
Example 13
Source File: DefaultOutlineCellRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Icon getDefaultClosedIcon() {
return UIManager.getIcon("Tree.closedIcon"); //NOI18N
   }
 
Example 14
Source File: OutlineComboBox.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Icon getExpandedIcon() {
    return UIManager.getIcon ("Tree.expandedIcon"); //NOI18N
}
 
Example 15
Source File: DefaultOutlineCellRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static Icon getCollapsedIcon() {
    return UIManager.getIcon ("Tree.collapsedIcon"); //NOI18N
}
 
Example 16
Source File: FlatButtonUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
@Override
protected void installDefaults( AbstractButton b ) {
	super.installDefaults( b );

	if( !defaults_initialized ) {
		String prefix = getPropertyPrefix();

		minimumWidth = UIManager.getInt( prefix + "minimumWidth" );
		iconTextGap = FlatUIUtils.getUIInt( prefix + "iconTextGap", 4 );

		background = UIManager.getColor( prefix + "background" );
		foreground = UIManager.getColor( prefix + "foreground" );

		startBackground = UIManager.getColor( prefix + "startBackground" );
		endBackground = UIManager.getColor( prefix + "endBackground" );
		focusedBackground = UIManager.getColor( prefix + "focusedBackground" );
		hoverBackground = UIManager.getColor( prefix + "hoverBackground" );
		pressedBackground = UIManager.getColor( prefix + "pressedBackground" );
		disabledBackground = UIManager.getColor( prefix + "disabledBackground" );
		disabledText = UIManager.getColor( prefix + "disabledText" );

		if( UIManager.getBoolean( "Button.paintShadow" ) ) {
			shadowWidth = FlatUIUtils.getUIInt( "Button.shadowWidth", 2 );
			shadowColor = UIManager.getColor( "Button.shadowColor" );
			defaultShadowColor = UIManager.getColor( "Button.default.shadowColor" );
		} else {
			shadowWidth = 0;
			shadowColor = null;
			defaultShadowColor = null;
		}

		defaultBackground = FlatUIUtils.getUIColor( "Button.default.startBackground", "Button.default.background" );
		defaultEndBackground = UIManager.getColor( "Button.default.endBackground" );
		defaultForeground = UIManager.getColor( "Button.default.foreground" );
		defaultFocusedBackground = UIManager.getColor( "Button.default.focusedBackground" );
		defaultHoverBackground = UIManager.getColor( "Button.default.hoverBackground" );
		defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
		defaultBoldText = UIManager.getBoolean( "Button.default.boldText" );

		toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
		toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
		toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );

		helpButtonIcon = UIManager.getIcon( "HelpButton.icon" );

		defaults_initialized = true;
	}

	if( startBackground != null ) {
		Color bg = b.getBackground();
		if( bg == null || bg instanceof UIResource )
			b.setBackground( startBackground );
	}

	LookAndFeel.installProperty( b, "opaque", false );
	LookAndFeel.installProperty( b, "iconTextGap", scale( iconTextGap ) );

	MigLayoutVisualPadding.install( b );
}
 
Example 17
Source File: DefaultTableHeaderRenderer.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Icon sortIcon = null;
   // setBackground(Constants.DS_BACK);
    boolean isPaintingForPrint = false;

    if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
            Color fgColor = null;
            Color bgColor = null;
            if (hasFocus) {
                fgColor = UIManager.getColor("TableHeader.focusCellForeground");
                bgColor = UIManager.getColor("TableHeader.focusCellBackground");
            }
            if (fgColor == null) {
                fgColor = header.getForeground();
            }
            if (bgColor == null) {
                bgColor = header.getBackground();
            }

            setFont(header.getFont());
            isPaintingForPrint = header.isPaintingForPrint();
        }

        if (!isPaintingForPrint && table.getRowSorter() != null) {
            if (!horizontalTextPositionSet) {
                // There is a row sorter, and the developer hasn't
                // set a text position, change to leading.
                setHorizontalTextPosition(JLabel.LEADING);
            }
            java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
            if (sortKeys.size() > 0
                    && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) {
                switch (sortKeys.get(0).getSortOrder()) {
                    case ASCENDING:
                        sortIcon = UIManager.getIcon("Table.ascendingSortIcon");
                        break;
                    case DESCENDING:
                        sortIcon = UIManager.getIcon("Table.descendingSortIcon");
                        break;
                    case UNSORTED:
                        sortIcon = UIManager.getIcon("Table.naturalSortIcon");
                        break;
                }
            }
        }
    }

    setText(value == null ? "" : value.toString());
    setIcon(sortIcon);

    Border border = null;
    if (hasFocus) {
        border = UIManager.getBorder("TableHeader.focusCellBorder");
    }
    if (border == null) {
        border = UIManager.getBorder("TableHeader.cellBorder");
    }
    setBorder(border);

    return this;
}
 
Example 18
Source File: ExtendedExample.java    From SpeechToText-REST with MIT License 4 votes vote down vote up
public ExtendedExample() {

    super(new BorderLayout());

    keyField = new JTextField(32);
    modeBox = new JComboBox<>(SpeechAPI.RecognitionMode.values());
    languageBox = new JComboBox<>(SpeechAPI.Language.values());
    formatBox = new JComboBox<>(SpeechAPI.OutputFormat.values());

    log = new JTextArea(20, 40);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    log.setLineWrap(true);
    JScrollPane logScrollPane = new JScrollPane(log);

    fc = new JFileChooser();
    fc.setFileFilter(new FileNameExtensionFilter("WAV audio files", "wav"));

    openButton = new JButton("Transcribe File", UIManager.getIcon("FileView.directoryIcon"));
    openButton.addActionListener(this);

    micButton = new JButton("Use Microphone", UIManager.getIcon("Tree.expandedIcon"));
    micButton.addActionListener(this);

    JPanel midPanel = new JPanel();
    midPanel.add(openButton);
    midPanel.add(micButton);

    JPanel knobs = new JPanel(new GridLayout(0, 2));
    knobs.add(new JLabel("Recognition mode:"));
    knobs.add(modeBox);
    knobs.add(new JLabel("Recognition language:"));
    knobs.add(languageBox);
    knobs.add(new JLabel("Output format:"));
    knobs.add(formatBox);

    midPanel.add(knobs);

    openButton.setEnabled(false);
    micButton.setEnabled(false);

    JPanel keyPanel = new JPanel();
    keyPanel.add(new JLabel("Please, enter your subscription key:"));
    keyPanel.add(keyField);
    keyField.setEditable(true);

    keyField.addActionListener((ActionEvent e) -> {
      if (bootstrapped)
        return;

      String text = keyField.getText();
      if (text != null && text.length() == 32) {
        log.append(String.format("Using subscription key '%s' to  generate an access token...", text));
        CompletableFuture.supplyAsync(() -> {
          return new RenewableAuthentication(text);
        }).thenAccept(this::bootstrap);
      } else if (text != null) {
        log.append(String.format("Subscription key is too %s.\n", text.length() < 32 ? "short" : "long"));
      }
    });

    add(keyPanel, BorderLayout.NORTH);
    add(midPanel, BorderLayout.CENTER);
    add(logScrollPane, BorderLayout.SOUTH);

    languageBox.setSelectedItem(SpeechAPI.Language.en_US);
  }
 
Example 19
Source File: BusyIcon.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * <p>Creates a new instance.</p>
 * <p>
 * The implementation first checks <code>UIManager</code> defaults and looks for <code>Icon</code>
 * under keys <code>"nb.tabcontrol.busy.icon.selected"</code> and <code>"nb.tabcontrol.busy.icon.normal"</code>.
 * If there is an Icon under those keys then the created instance will rotate
 * that Icon to animate it.
 * </p><p>
 * If there are no Icons in UIManager then there will be an attempt to create
 * animated Icon based <code>BusyPainter</code> in SwingX library. If swingx.jar
 * is available on classpath then reflection is used to create BusyPainter
 * instance and paint icon animations with it.
 * </p><p>
 * If SwingX library isn't available then the default image 
 * <code>"org/netbeans/swing/tabcontrol/resources/busy_icon.png"</code>
 * will be rotated.
 * </p>
 * 
 * @param selectedTab Boolean to create icon for selected tab state, false
 * to create icon for normal tab state.
 * @return Animated icon.
 */
public static BusyIcon create( boolean selectedTab ) {
    BusyIcon res = null;
    Icon img = UIManager.getIcon( "nb.tabcontrol.busy.icon." + (selectedTab ? "selected" : "normal") ); //NOI18N
    if( null != img ) {
        res = new ImageBusyIcon( ImageUtilities.icon2Image( img ) );
    } else {
        res = SwingXBusyIcon.create();
    }
    if( null == res )
        res = new ImageBusyIcon( ImageUtilities.loadImage( "org/netbeans/swing/tabcontrol/resources/busy_icon.png") ); //NOI18N
    return res;
}
 
Example 20
Source File: RemoteFileSystemView.java    From rapidminer-studio with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Icon for a file, directory, or folder as it would be displayed in a system file browser. The
 * default implementation returns the standard icon of either a folder or a file.
 *
 */
@Override
public Icon getSystemIcon(File f) {
	return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
}