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

The following examples show how to use javax.swing.UIManager#getLookAndFeel() . 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: JSystemFileChooser.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public void updateUI(){
    LookAndFeel old = UIManager.getLookAndFeel();
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (Throwable ex) {
        old = null;
    }

    super.updateUI();

    if(old != null){
        FilePane filePane = findFilePane(this);
        filePane.setViewType(FilePane.VIEWTYPE_DETAILS);
        filePane.setViewType(FilePane.VIEWTYPE_LIST);

        Color background = UIManager.getColor("Label.background");
        setBackground(background);
        setOpaque(true);

        try {
            UIManager.setLookAndFeel(old);
        }
        catch (UnsupportedLookAndFeelException ignored) {} // shouldn't get here
    }
}
 
Example 2
Source File: DPreferences.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void initLookAndFeelSelection() {
	// This may contain duplicates
	UIManager.LookAndFeelInfo[] lookFeelInfos = UIManager.getInstalledLookAndFeels();
	LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
	TreeSet<String> lookFeelClasses = new TreeSet<>();

	for (UIManager.LookAndFeelInfo lfi : lookFeelInfos) {
		// Avoid duplicates
		if (!lookFeelClasses.contains(lfi.getClassName())) {
			lookFeelClasses.add(lfi.getClassName());

			lookFeelInfoList.add(lfi);
			jcbLookFeel.addItem(lfi.getName());

			// Pre-select current look & feel - compare by class as the look
			// and feel name can differ from the look and feel info name
			if ((currentLookAndFeel != null)
					&& (currentLookAndFeel.getClass().getName().equals(lfi.getClassName()))) {
				this.lookFeelInfo = lfi;
				jcbLookFeel.setSelectedIndex(jcbLookFeel.getItemCount() - 1);
			}
		}
	}
}
 
Example 3
Source File: FlatRootPaneUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
protected void installDefaults( JRootPane c ) {
	super.installDefaults( c );

	// Update background color of JFrame or JDialog parent to avoid bad border
	// on HiDPI screens when switching from light to dark Laf.
	// The background of JFrame is initialized in JFrame.frameInit() and
	// the background of JDialog in JDialog.dialogInit(),
	// but it was not updated when switching Laf.
	Container parent = c.getParent();
	if( parent instanceof JFrame || parent instanceof JDialog ) {
		Color background = parent.getBackground();
		if( background == null || background instanceof UIResource )
			parent.setBackground( UIManager.getColor( "control" ) );
	}

	// enable dark window appearance on macOS when running in JetBrains Runtime
	if( SystemInfo.IS_JETBRAINS_JVM && SystemInfo.IS_MAC_OS_10_14_MOJAVE ) {
		LookAndFeel laf = UIManager.getLookAndFeel();
		boolean isDark = laf instanceof FlatLaf && ((FlatLaf)laf).isDark();
		c.putClientProperty( "jetbrains.awt.windowDarkAppearance", isDark );
	}
}
 
Example 4
Source File: BasicLookAndFeel.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
Example 5
Source File: BasicLookAndFeel.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the parent of the passed in ActionMap to be the audio action
 * map.
 */
static void installAudioActionMap(ActionMap map) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        map.setParent(((BasicLookAndFeel)laf).getAudioActionMap());
    }
}
 
Example 6
Source File: BasicLookAndFeel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
Example 7
Source File: DesktopProperty.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent pce) {
    DesktopProperty property = get();

    if (property == null || laf != UIManager.getLookAndFeel()) {
        // The property was GC'ed, we're no longer interested in
        // PropertyChanges, remove the listener.
        dispose();
    }
    else {
        property.invalidate(laf);
        property.updateUI();
    }
}
 
Example 8
Source File: BasicLookAndFeel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
Example 9
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * Factory methods for obtaining the current <code>LayoutStyle</code> object
 * appropriate for the current look and feel.
 * 
 * @return the current LayoutStyle instance
 */
public static LayoutStyle getSharedInstance() {
	Object layoutImpl = UIManager.get("LayoutStyle.instance");
	if (layoutImpl != null && (layoutImpl instanceof LayoutStyle)) {
		return (LayoutStyle) layoutImpl;
	}
	LookAndFeel currentLAF = UIManager.getLookAndFeel();
	if (layoutStyle == null || currentLAF != laf) {
		laf = currentLAF;
		String lafID = laf.getID();
		if (USE_CORE_LAYOUT_STYLE) {
			if ("Aqua" == lafID) {
				try {
					currentLAF.getClass().getDeclaredMethod("getLayoutStyle", new Class[0]);
					layoutStyle = new SwingLayoutStyle();
				} catch (NoSuchMethodException nsfex) {
					// getLayoutStyle() not overriden => use our own (issue
					// 52)
					layoutStyle = new AquaLayoutStyle();
				}
			} else {
				layoutStyle = new SwingLayoutStyle();
			}
		} else if ("Metal" == lafID) {
			layoutStyle = new MetalLayoutStyle();
		} else if ("Windows" == lafID) {
			layoutStyle = new WindowsLayoutStyle();
		} else if ("GTK" == lafID) {
			layoutStyle = new GnomeLayoutStyle();
		} else if ("Aqua" == lafID) {
			layoutStyle = new AquaLayoutStyle();
		} else {
			layoutStyle = new LayoutStyle();
		}
	}
	return layoutStyle;
}
 
Example 10
Source File: BasicLookAndFeel.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method to play a named sound.
 *
 * @param c JComponent to play the sound for.
 * @param actionKey Key for the sound.
 */
static void playSound(JComponent c, Object actionKey) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        ActionMap map = c.getActionMap();
        if (map != null) {
            Action audioAction = map.get(actionKey);
            if (audioAction != null) {
                // pass off firing the Action to a utility method
                ((BasicLookAndFeel)laf).playSound(audioAction);
            }
        }
    }
}
 
Example 11
Source File: OSPRuntime.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the look and feel of the user interface.  Look and feel user interfaces are:
 *
 * NIMBUS_LF: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
 * METAL_LF: javax.swing.plaf.metal.MetalLookAndFeel
 * GTK_LF: com.sun.java.swing.plaf.gtk.GTKLookAndFeel
 * MOTIF_LF: com.sun.java.swing.plaf.motif.MotifLookAndFeel
 * WINDOWS_LF: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
 * DEFAULT_LF: the default look and feel in effect when this class was loaded
 * CROSS_PLATFORM_LF: the cross platform look and feel; usually METAL_LF
 * SYSTEM_LF: the operating system look and feel
 *
 * @param useDefaultLnFDecorations
 * @param lookAndFeel
 *
 * @return true if successful
 */
public static boolean setLookAndFeel(boolean useDefaultLnFDecorations, String lookAndFeel) {
  boolean found = true;
  LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
  try {
    if((lookAndFeel==null)||lookAndFeel.equals(DEFAULT_LF)) {
      UIManager.setLookAndFeel(DEFAULT_LOOK_AND_FEEL);
      useDefaultLnFDecorations = DEFAULT_LOOK_AND_FEEL_DECORATIONS;
    } else if(lookAndFeel.equals(CROSS_PLATFORM_LF)) {
      lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
      UIManager.setLookAndFeel(lookAndFeel);
    } else if(lookAndFeel.equals(SYSTEM_LF)) {
      lookAndFeel = UIManager.getSystemLookAndFeelClassName();
      UIManager.setLookAndFeel(lookAndFeel);
    } else if(lookAndFeel.equals(NIMBUS_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");   //$NON-NLS-1$
    } else if(lookAndFeel.equals(METAL_LF)) {
      //        MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
      UIManager.setLookAndFeel(new MetalLookAndFeel());
    } else if(lookAndFeel.equals(GTK_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");         //$NON-NLS-1$
    } else if(lookAndFeel.equals(MOTIF_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");     //$NON-NLS-1$
    } else if(lookAndFeel.equals(WINDOWS_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); //$NON-NLS-1$
    } else {
      UIManager.setLookAndFeel(lookAndFeel);                                          // LnF can be set using a fully qualified path
    }
    JFrame.setDefaultLookAndFeelDecorated(useDefaultLnFDecorations);
    JDialog.setDefaultLookAndFeelDecorated(useDefaultLnFDecorations);
  } catch(Exception ex) {
    found = false;
  }
  if(!found) { // keep current look and feel
    try {
      UIManager.setLookAndFeel(currentLookAndFeel);
    } catch(Exception e) {}
  }
  return found;
}
 
Example 12
Source File: BasicLookAndFeel.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the parent of the passed in ActionMap to be the audio action
 * map.
 */
static void installAudioActionMap(ActionMap map) {
    LookAndFeel laf = UIManager.getLookAndFeel();
    if (laf instanceof BasicLookAndFeel) {
        map.setParent(((BasicLookAndFeel)laf).getAudioActionMap());
    }
}
 
Example 13
Source File: ProgressPanel.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setIndeterminate(boolean indeterminate) {
  // workaround for bug in some versions of Aqua L&F that prevents GATE
  // from exiting if indeterminate progress bars are used
  if(Gate.runningOnMac() && (UIManager.getLookAndFeel() == null
      || UIManager.getLookAndFeel().getClass().getName()
          .equals(UIManager.getSystemLookAndFeelClassName()))) {
    return;
  } else {
    super.setIndeterminate(indeterminate);
  }
}
 
Example 14
Source File: DefaultTreeCellRenderer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}
 
Example 15
Source File: DefaultsDisplay.java    From littleluck with Apache License 2.0 4 votes vote down vote up
protected void addDefaultsTab() {
    LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
    JScrollPane scrollPane = new JScrollPane(createDefaultsTable());
    tabPane.addTab(lookAndFeel.getName() + " Defaults", scrollPane);
    defaultsTablesMap.put(lookAndFeel.getName(), scrollPane);
}
 
Example 16
Source File: DefaultTreeCellRenderer.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}
 
Example 17
Source File: TriStateCheckBox.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
private boolean isThirdStateSupported() {
	LookAndFeel laf = UIManager.getLookAndFeel();
	return laf instanceof FlatLaf || laf.getClass().getName().equals( "com.apple.laf.AquaLookAndFeel" );
}
 
Example 18
Source File: DefaultTreeCellRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}
 
Example 19
Source File: DefaultTreeCellRenderer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}
 
Example 20
Source File: DefaultTreeCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Configures the renderer based on the passed in components.
  * The value is set from messaging the tree with
  * <code>convertValueToText</code>, which ultimately invokes
  * <code>toString</code> on <code>value</code>.
  * The foreground color is set based on the selection and the icon
  * is set based on the <code>leaf</code> and <code>expanded</code>
  * parameters.
  */
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    String         stringValue = tree.convertValueToText(value, sel,
                                      expanded, leaf, row, hasFocus);

    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);

    Color fg = null;
    isDropCell = false;

    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null
            && dropLocation.getChildIndex() == -1
            && tree.getRowForPath(dropLocation.getPath()) == row) {

        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }

        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }

    setForeground(fg);

    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }

    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null) icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());

    selected = sel;

    return this;
}