javax.swing.plaf.basic.BasicLookAndFeel Java Examples

The following examples show how to use javax.swing.plaf.basic.BasicLookAndFeel. 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: KnopflerfishLookAndFeel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void initComponentDefaults(UIDefaults table) {
  super.initComponentDefaults( table );

  // I'll have to copy some of the resource definitions here, since the
  // original code in BasicLookAndFeel (from which we inherit) uses
  // getClass() to find its resources. That will fail since my
  // classloader does not have these resources.
  //
  // So, the trick is to replace getClass() with MetalLookAndFeel.class

  Object[] defaults = {
    "OptionPane.errorIcon",       LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Error.gif"),
    "OptionPane.informationIcon", LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Inform.gif"),
    "OptionPane.warningIcon",     LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Warn.gif"),
    "OptionPane.questionIcon",    LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Question.gif"),

    "InternalFrame.icon",         LookAndFeel.makeIcon(BasicLookAndFeel.class, "icons/JavaCup.gif"),


    // Button margin slightly smaller than metal to save space
    "Button.margin", new InsetsUIResource(1, 11, 1, 11),


  };
  table.putDefaults(defaults);
}
 
Example #2
Source File: MaterialLookAndFeel.java    From material-ui-swing with MIT License 6 votes vote down vote up
@Override
public UIDefaults getDefaults() {
	try {
		final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
		superMethod.setAccessible(true);
		final UIDefaults defaults = (UIDefaults) superMethod.invoke(basicLookAndFeel);
		initClassDefaults(defaults);
		initComponentDefaults(defaults);
		theme.installTheme();
		defaults.put("OptionPane.warningIcon", MaterialImageFactory.getInstance().getImage(MaterialImageFactory.WARNING));
		defaults.put("OptionPane.errorIcon", MaterialImageFactory.getInstance().getImage(MaterialImageFactory.ERROR));
		defaults.put("OptionPane.questionIcon", MaterialImageFactory.getInstance().getImage(MaterialImageFactory.QUESTION));
		defaults.put("OptionPane.informationIcon", MaterialImageFactory.getInstance().getImage(MaterialImageFactory.INFORMATION));
		return defaults;
	} catch (Exception ignore) {
		//do nothing
		ignore.printStackTrace();
	}
	return super.getDefaults();
}
 
Example #3
Source File: MaterialLookAndFeel.java    From material-ui-swing with MIT License 6 votes vote down vote up
public static void changeTheme(MaterialTheme theme) {
	if (theme == null) {
		throw new IllegalArgumentException("Theme null");
	}
	BasicLookAndFeel blaf = (BasicLookAndFeel) UIManager.getLookAndFeel();
	if (blaf instanceof MaterialLookAndFeel) {
		MaterialLookAndFeel materialLookAndFeel = (MaterialLookAndFeel) blaf;
		UIManager.removeAuxiliaryLookAndFeel(materialLookAndFeel);
		theme.installTheme();
		materialLookAndFeel.setTheme(theme);
		try {
			UIManager.setLookAndFeel(materialLookAndFeel);
		} catch (UnsupportedLookAndFeelException e) {
			throw new MaterialChangeThemeException("Exception generated when I change the theme\nError exception is: " + e.getLocalizedMessage());
		}
		return;
	}

	throw new MaterialChangeThemeException("The look and feel setted not is MaterialLookAnfFeel");
}
 
Example #4
Source File: Appearance.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
private UIManager.LookAndFeelInfo[] getLookAndFeels() {
  final List<UIManager.LookAndFeelInfo> installed = Arrays
    .stream(UIManager.getInstalledLookAndFeels())
    .filter(ui -> !ui.getName().toLowerCase().matches("cde/motif|metal|windows classic|nimbus"))
    .collect(Collectors.toList());

  final List<BasicLookAndFeel> substance = Arrays.asList(
    new SubstanceBusinessLookAndFeel(),
    new SubstanceGraphiteAquaLookAndFeel()
  );

  final List<UIManager.LookAndFeelInfo> extraLf =
    substance.stream()
      .map(l -> new UIManager.LookAndFeelInfo(l.getName(), l.getClass().getName()))
      .collect(Collectors.toList());
  final ArrayList<UIManager.LookAndFeelInfo> result = new ArrayList<>();
  result.addAll(installed);
  result.addAll(extraLf);
  return result.toArray(new UIManager.LookAndFeelInfo[0]);
}
 
Example #5
Source File: ModernDarkLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModernDarkLaf() {
  try {
    if (SystemInfo.isWindows || SystemInfo.isLinux) {
      base = new IntelliJMetalLookAndFeel();
    }
    else {
      final String name = UIManager.getSystemLookAndFeelClassName();
      base = (BasicLookAndFeel)Class.forName(name).newInstance();
    }
  }
  catch (Exception e) {
    log(e);
  }
}
 
Example #6
Source File: Test6984643.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #7
Source File: Test6984643.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #8
Source File: Test6984643.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #9
Source File: DarculaLaf.java    From Darcula with Apache License 2.0 5 votes vote down vote up
private void callInit(String method, UIDefaults defaults) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method, UIDefaults.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #10
Source File: DarculaLaf.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
public UIDefaults getDefaults() {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
    superMethod.setAccessible(true);
    final UIDefaults metalDefaults =
        (UIDefaults)superMethod.invoke(new MetalLookAndFeel());
    final UIDefaults defaults = (UIDefaults)superMethod.invoke(base);
    initInputMapDefaults(defaults);
    initIdeaDefaults(defaults);
    patchStyledEditorKit();
    patchComboBox(metalDefaults, defaults);
    defaults.remove("Spinner.arrowButtonBorder");
    defaults.put("Spinner.arrowButtonSize", new Dimension(16, 5));
    defaults.put("Tree.collapsedIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/treeNodeCollapsed.png")));
    defaults.put("Tree.expandedIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/treeNodeExpanded.png")));
    defaults.put("Menu.arrowIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/menuItemArrowIcon.png")));
    defaults.put("CheckBoxMenuItem.checkIcon", EmptyIcon.create(16));
    defaults.put("RadioButtonMenuItem.checkIcon", EmptyIcon.create(16));
    defaults.put("InternalFrame.icon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/internalFrame.png")));
    defaults.put("OptionPane.informationIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_info.png")));
    defaults.put("OptionPane.questionIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_question.png")));
    defaults.put("OptionPane.warningIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_warning.png")));
    defaults.put("OptionPane.errorIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_error.png")));
    if (SystemInfo.isMac && !"true".equalsIgnoreCase(System.getProperty("apple.laf.useScreenMenuBar", "false"))) {
      defaults.put("MenuBarUI", "com.bulenkov.darcula.ui.DarculaMenuBarUI");
      defaults.put("MenuUI", "javax.swing.plaf.basic.BasicMenuUI");
    }
    return defaults;
  }
  catch (Exception ignore) {
    log(ignore);
  }
  return super.getDefaults();
}
 
Example #11
Source File: DarculaLaf.java    From Darcula with Apache License 2.0 5 votes vote down vote up
private void call(String method) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method);
    superMethod.setAccessible(true);
    superMethod.invoke(base);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #12
Source File: DarculaLaf.java    From Darcula with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadSystemColors(UIDefaults defaults, String[] systemColors, boolean useNative) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("loadSystemColors",
        UIDefaults.class,
        String[].class,
        boolean.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults, systemColors, useNative);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #13
Source File: Test6984643.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #14
Source File: ModernDarkLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void callInit(String method, UIDefaults defaults) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method, UIDefaults.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults);
  }
  catch (Exception e) {
    log(e);
  }
}
 
Example #15
Source File: ModernDarkLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public UIDefaults getDefaultsImpl(UIDefaults superDefaults) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
    superMethod.setAccessible(true);
    final UIDefaults metalDefaults = (UIDefaults)superMethod.invoke(new MetalLookAndFeel());
    final UIDefaults defaults = (UIDefaults)superMethod.invoke(base);
    if (SystemInfo.isLinux && !Registry.is("darcula.use.native.fonts.on.linux")) {
      Font font = findFont("DejaVu Sans");
      if (font != null) {
        for (Object key : defaults.keySet()) {
          if (key instanceof String && ((String)key).endsWith(".font")) {
            defaults.put(key, new FontUIResource(font.deriveFont(13f)));
          }
        }
      }
    }

    LafManagerImplUtil.initInputMapDefaults(defaults);
    defaults.put(SupportTextBoxWithExpandActionExtender.class, SupportTextBoxWithExpandActionExtender.INSTANCE);
    defaults.put(SupportTextBoxWithExtensionsExtender.class, SupportTextBoxWithExtensionsExtender.INSTANCE);

    initIdeaDefaults(defaults);
    patchStyledEditorKit(defaults);
    patchComboBox(metalDefaults, defaults);
    defaults.remove("Spinner.arrowButtonBorder");
    defaults.put("Spinner.arrowButtonSize", new Dimension(16, 5));

    MetalLookAndFeel.setCurrentTheme(createMetalTheme());

    defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
    return defaults;
  }
  catch (Exception e) {
    log(e);
  }
  return super.getDefaultsImpl(superDefaults);
}
 
Example #16
Source File: ModernDarkLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void call(String method) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method);
    superMethod.setAccessible(true);
    superMethod.invoke(base);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #17
Source File: ModernDarkLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadSystemColors(UIDefaults defaults, String[] systemColors, boolean useNative) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("loadSystemColors", UIDefaults.class, String[].class, boolean.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults, systemColors, useNative);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #18
Source File: BegMenuItemUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Copied from BasicMenuItemUI
 */
private void doClick(MenuSelectionManager msm, MouseEvent e) {
  // Auditory cue
  if (!isInternalFrameSystemMenu()) {
    @NonNls ActionMap map = menuItem.getActionMap();
    if (map != null) {
      Action audioAction = map.get(getPropertyPrefix() + ".commandSound");
      if (audioAction != null) {
        // pass off firing the Action to a utility method
        BasicLookAndFeel lf = (BasicLookAndFeel)UIManager.getLookAndFeel();
        // It's a hack. The method BasicLookAndFeel.playSound has protected access, so
        // it's imposible to mormally invoke it.
        try {
          Method playSoundMethod = BasicLookAndFeel.class.getDeclaredMethod(PLAY_SOUND_METHOD, new Class[]{Action.class});
          playSoundMethod.setAccessible(true);
          playSoundMethod.invoke(lf, new Object[]{audioAction});
        }
        catch (Exception ignored) {
        }
      }
    }
  }
  // Visual feedback
  if (msm == null) {
    msm = MenuSelectionManager.defaultManager();
  }
  msm.clearSelectedPath();
  menuItem.doClick(0);
}
 
Example #19
Source File: DarculaLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
public DarculaLaf() {
  try {
    if (SystemInfo.isWindows || SystemInfo.isLinux) {
      base = new IntelliJMetalLookAndFeel();
    } else {
      final String name = UIManager.getSystemLookAndFeelClassName();
      base = (BasicLookAndFeel)Class.forName(name).newInstance();
    }
  }
  catch (Exception e) {
    log(e);
  }
}
 
Example #20
Source File: DarculaLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void callInit(String method, UIDefaults defaults) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method, UIDefaults.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults);
  }
  catch (Exception e) {
    log(e);
  }
}
 
Example #21
Source File: DarculaLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void call(String method) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method);
    superMethod.setAccessible(true);
    superMethod.invoke(base);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #22
Source File: DarculaLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void loadSystemColors(UIDefaults defaults, String[] systemColors, boolean useNative) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("loadSystemColors",
                                                                        UIDefaults.class,
                                                                        String[].class,
                                                                        boolean.class);
    superMethod.setAccessible(true);
    superMethod.invoke(base, defaults, systemColors, useNative);
  }
  catch (Exception ignore) {
    log(ignore);
  }
}
 
Example #23
Source File: ModernMenuItemUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Copied from BasicMenuItemUI
 */
private void doClick(MenuSelectionManager msm, MouseEvent e) {
  // Auditory cue
  if (!isInternalFrameSystemMenu()) {
    @NonNls ActionMap map = menuItem.getActionMap();
    if (map != null) {
      Action audioAction = map.get(getPropertyPrefix() + ".commandSound");
      if (audioAction != null) {
        // pass off firing the Action to a utility method
        BasicLookAndFeel lf = (BasicLookAndFeel)UIManager.getLookAndFeel();
        // It's a hack. The method BasicLookAndFeel.playSound has protected access, so
        // it's imposible to mormally invoke it.
        try {
          Method playSoundMethod = BasicLookAndFeel.class.getDeclaredMethod(PLAY_SOUND_METHOD, new Class[]{Action.class});
          playSoundMethod.setAccessible(true);
          playSoundMethod.invoke(lf, new Object[]{audioAction});
        }
        catch (Exception ignored) {
        }
      }
    }
  }
  // Visual feedback
  if (msm == null) {
    msm = MenuSelectionManager.defaultManager();
  }
  msm.clearSelectedPath();
  menuItem.doClick(0);
}
 
Example #24
Source File: UIDefaultsDump.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private void dump( PrintWriter out, Predicate<String> keyFilter ) {
	Class<?> lookAndFeelClass = lookAndFeel instanceof MyBasicLookAndFeel
		? BasicLookAndFeel.class
		: lookAndFeel.getClass();
	out.printf( "Class  %s%n", lookAndFeelClass.getName() );
	out.printf( "ID     %s%n", lookAndFeel.getID() );
	out.printf( "Name   %s%n", lookAndFeel.getName() );
	out.printf( "Java   %s%n", System.getProperty( "java.version" ) );
	out.printf( "OS     %s%n", System.getProperty( "os.name" ) );

	defaults.entrySet().stream()
		.sorted( (key1, key2) -> {
			return String.valueOf( key1 ).compareTo( String.valueOf( key2 ) );
		} )
		.forEach( entry -> {
			Object key = entry.getKey();
			Object value = entry.getValue();

			String strKey = String.valueOf( key );
			if( !keyFilter.test( strKey ) )
				return;

			int dotIndex = strKey.indexOf( '.' );
			String prefix = (dotIndex > 0)
				? strKey.substring( 0, dotIndex )
				: strKey.endsWith( "UI" )
					? strKey.substring( 0, strKey.length() - 2 )
					: "";
			if( !prefix.equals( lastPrefix ) ) {
				lastPrefix = prefix;
				out.printf( "%n%n#---- %s ----%n%n", prefix );
			}

			out.printf( "%-30s ", strKey );
			dumpValue( out, value );
			out.println();
		} );
}
 
Example #25
Source File: Test6984643.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #26
Source File: MaterialLookAndFeel.java    From material-ui-swing with MIT License 5 votes vote down vote up
protected void call(String method) {
	try {
		final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method);
		superMethod.setAccessible(true);
		superMethod.invoke(basicLookAndFeel);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example #27
Source File: Test6984643.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #28
Source File: Test6984643.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #29
Source File: Test6984643.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}
 
Example #30
Source File: Test6984643.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new BasicLookAndFeel() {
        public String getName() {
            return "A name";
        }

        public String getID() {
            return "An id";
        }

        public String getDescription() {
            return "A description";
        }

        public boolean isNativeLookAndFeel() {
            return false;
        }

        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new JFileChooser();
        }
    });
}