List of usage examples for javax.swing UIManager get
public static Object get(Object key)
From source file:com.willwinder.universalgcodesender.ExperimentalWindow.java
/** * @param args the command line arguments *//* w ww . j ava 2s .com*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ExperimentalWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> // Fix look and feel to use CMD+C/X/V/A instead of CTRL if (SystemUtils.IS_OS_MAC) { Collection<InputMap> ims = new ArrayList<>(); ims.add((InputMap) UIManager.get("TextField.focusInputMap")); ims.add((InputMap) UIManager.get("TextArea.focusInputMap")); ims.add((InputMap) UIManager.get("EditorPane.focusInputMap")); ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap")); ims.add((InputMap) UIManager.get("PasswordField.focusInputMap")); ims.add((InputMap) UIManager.get("TextPane.focusInputMap")); int c = KeyEvent.VK_C; int v = KeyEvent.VK_V; int x = KeyEvent.VK_X; int a = KeyEvent.VK_A; int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); for (InputMap im : ims) { im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction); im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction); im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction); im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction); } } /* Create the form */ // GUIBackend backend = new GUIBackend(); final ExperimentalWindow mw = new ExperimentalWindow(); /* Apply the settings to the ExperimentalWindow bofore showing it */ mw.setSize(mw.backend.getSettings().getMainWindowSettings().width, mw.backend.getSettings().getMainWindowSettings().height); mw.setLocation(mw.backend.getSettings().getMainWindowSettings().xLocation, mw.backend.getSettings().getMainWindowSettings().yLocation); mw.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { mw.backend.getSettings().getMainWindowSettings().height = ce.getComponent().getSize().height; mw.backend.getSettings().getMainWindowSettings().width = ce.getComponent().getSize().width; } @Override public void componentMoved(ComponentEvent ce) { mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); /* Display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { mw.setVisible(true); } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { mw.connectionPanel.saveSettings(); mw.commandPanel.saveSettings(); if (mw.pendantUI != null) { mw.pendantUI.stop(); } } }); }
From source file:Main.java
public static void setFontSize(int size) { for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof FontUIResource) { UIManager.put(key, ((FontUIResource) value).deriveFont((float) size)); }// w w w.j ava2 s . c om } }
From source file:Main.java
/** * Returns the default "Label.font" as used by Swing's UIManager. *///from ww w.j av a2 s .c om public static Font getUIFont() { return (Font) UIManager.get("Label.font"); // and NOT: return (Font)UIManager.getLookAndFeelDefaults().get("Label.font"); }
From source file:Main.java
public static void setUIFont(Font f) { ///*ww w .java 2 s. c om*/ // sets the default font for all Swing components. // ex. // setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12)); // FontUIResource fur = new FontUIResource(f); java.util.Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, fur); } }
From source file:Main.java
public static void setUIFont(FontUIResource f) { ///*from w w w . j av a2s.c o m*/ // sets the default FONT for all Swing components. // ex. // setUIFont (new javax.swing.plaf.FontUIResource // ("Serif",Font.ITALIC,12)); // Enumeration<Object> keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof FontUIResource) UIManager.put(key, f); } }
From source file:Main.java
public static void setLookAndFeel(int fontSize) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if ((key instanceof String) && (((String) key).endsWith(".font"))) { FontUIResource font = (FontUIResource) UIManager.get(key); defaults.put(key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize)); }// w ww . j av a 2 s . co m } }
From source file:Main.java
/** * Returns a string with all fonts used by Swing's UIManager. *//*from w w w . j av a 2s . c om*/ public static String getUIFonts() { final StringBuffer fonts = new StringBuffer(128); fonts.append("Default font: "); fonts.append(getUIFont().toString()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); String lf = System.getProperty("line.separator"); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " " + ifont.getSize()); } } return fonts.toString(); }
From source file:Main.java
/** * Sets all used fonts for displaying to the specified font df * <br>Use with care! /*from w ww . j a va2s . co m*/ */ public static void setUIFont(final Font df) { setUIFontSize(df.getSize()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize()); UIManager.put(key, ofont); } } }
From source file:Main.java
/** * Code from http://stackoverflow.com/questions/1236231/managing-swing-ui-default-font-sizes-without-quaqua * @param fontSize/*from www. j a v a 2s. c om*/ */ public static void changeDefaultFontSize(int fontSize) { UIDefaults defaults = UIManager.getDefaults(); // UIDefaults defaults = UIManager.getLookAndFeelDefaults(); Enumeration<Object> keys = defaults.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if ((key instanceof String) && (((String) key).endsWith(".font"))) { FontUIResource font = (FontUIResource) UIManager.get(key); defaults.put(key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize)); } } }
From source file:Main.java
public static void increaseDefaultFont(float multiplier) { for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value != null && value instanceof FontUIResource) { FontUIResource fontUIResource = (FontUIResource) value; UIManager.put(key, fontUIResource.deriveFont(fontUIResource.getSize() * multiplier)); }//from w w w . ja v a 2 s . co m } }