Example usage for javax.swing.plaf FontUIResource FontUIResource

List of usage examples for javax.swing.plaf FontUIResource FontUIResource

Introduction

In this page you can find the example usage for javax.swing.plaf FontUIResource FontUIResource.

Prototype

public FontUIResource(String name, int style, int size) 

Source Link

Document

Constructs a FontUIResource .

Usage

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));
        }//from  w w  w.  j a  v  a2  s .c om
    }
}

From source file:Main.java

/**
 * Code from http://stackoverflow.com/questions/1236231/managing-swing-ui-default-font-sizes-without-quaqua
 * @param fontSize/* w w  w  . j ava2 s. co  m*/
 */
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

/** 
 * Sets all used fonts for displaying to the specified font df
 * <br>Use with care! //from www. java  2 s . 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:mergedoc.Application.java

/**
 * ? Look & Feel ???/* ww w .  j a v  a2 s  .  c o m*/
 * @throws ClassNotFoundException LookAndFeel ????????
 * @throws InstantiationException ????????????
 * @throws IllegalAccessException ????????????
 * @throws UnsupportedLookAndFeelException lnf.isSupportedLookAndFeel() ? false ??
 */
private static void initSystemLookAndFeel() throws ClassNotFoundException, InstantiationException,
        IllegalAccessException, UnsupportedLookAndFeelException {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    Toolkit.getDefaultToolkit().setDynamicLayout(true);

    // Windows ???
    String osName = System.getProperty("os.name", "");
    if (osName.indexOf("Windows") != -1) {

        Object propoFont = new FontUIResource("MS UI Gothic", Font.PLAIN, 12);
        Object fixedFont = new FontUIResource("MS Gothic", Font.PLAIN, 12);

        // ??????????
        // ????? instanceof FontUIResource ?
        // ???UIDefaults ? Lazy Value ??????
        for (Object keyObj : UIManager.getLookAndFeelDefaults().keySet()) {
            String key = keyObj.toString();
            if (key.endsWith("font") || key.endsWith("Font")) {
                UIManager.put(key, propoFont);
            }
        }

        // ?????
        UIManager.put("OptionPane.messageFont", fixedFont);
        UIManager.put("TextPane.font", fixedFont);
        UIManager.put("TextArea.font", fixedFont);
    }
}

From source file:com.diversityarrays.kdxplore.KDXplore.java

static public void setUIfontSize(float multiplier) {
    UIDefaults defaults = UIManager.getDefaults();
    for (Enumeration<?> e = defaults.keys(); e.hasMoreElements();) {
        Object key = e.nextElement();
        Object value = defaults.get(key);
        if (value instanceof Font) {
            Font font = (Font) value;
            int newSize = Math.round(font.getSize() * multiplier);
            if (value instanceof FontUIResource) {
                defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), newSize));
            } else {
                defaults.put(key, new Font(font.getName(), font.getStyle(), newSize));
            }/*w w w  .ja v a2s .co m*/
        } else if (value instanceof Integer) {
            if ("Tree.rowHeight".equals(key)) { //$NON-NLS-1$
                // System.out.println(key+": "+value);
                Integer rh = (Integer) value;
                rh = (int) (rh * multiplier * 1.4);
                defaults.put(key, rh);
            }
        }
    }
}

From source file:adapters.HistogramChartAdapter.java

/**
 * Modified method//from  ww  w  .  j  a  va2 s  .c om
 *
 * Displays chart on the screen using Swing.
 *    This method creates an application containing a chart panel displaying
 *    the chart. The created frame is positioned on-screen, and displayed before
 *    it is returned. The <TT>width</TT> and the <TT>height</TT>
 *    of the chart are measured in pixels.
 *
 * @param width frame width in pixels.
 *
 *    @param height frame height in pixels.
 *
 *    @return frame containing the chart.
 *
 */
public JFrame view(int width, int height) {
    JFrame myFrame;
    if (chart.getTitle() != null)
        myFrame = new JFrame("Histogram Chart: " + chart.getTitle().getText());
    else
        myFrame = new JFrame("Histogram Chart");
    TextTitle tt = chart.getTitle();
    tt.setFont(new FontUIResource("DensityChartSmallFont", Font.ITALIC, 12));
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    myFrame.setContentPane(chartPanel);
    myFrame.pack();
    myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    return myFrame;
}

From source file:king.flow.action.business.InsertCardAction.java

@Override
protected void installButtonAction() {
    JButton btn = (JButton) this.owner;
    btn.addActionListener(new ActionListener() {

        @Override/*from   w  w  w.ja  v a  2  s . c  o  m*/
        public void actionPerformed(ActionEvent e) {
            if (cardType == DeviceEnum.GZ_CARD) {
                progressTip = new JLabel(
                        getResourceMsg("operation.ic.card.insert.prompt" + "." + DeviceEnum.GZ_CARD.value()));
            } else {
                progressTip = new JLabel(getResourceMsg("operation.ic.card.insert.prompt"));
            }

            Window windowNode = getWindowNode();
            UiStyle uiStyle = windowNode.getUiStyle();
            if (uiStyle != null && uiStyle.getFont() != null && uiStyle.getFont().getName() != null) {
                progressTip.setFont(new FontUIResource(uiStyle.getFont().getName(), java.awt.Font.BOLD, 50));
            } else {
                progressTip.setFont(new FontUIResource("Dialog", java.awt.Font.BOLD, 50));
            }
            progressTip.setHorizontalAlignment(SwingConstants.CENTER);
            progressTip.setVerticalAlignment(SwingConstants.BOTTOM);
            final JDialog progressAnimation = buildAnimationDialog(animationFile);
            progressTip.setBounds(0, 120, progressAnimation.getBounds().width, 80);
            progressAnimation.getContentPane().add(progressTip, 1);
            final ImageIcon bgImage = CommonUtil.getImageIcon("/image/2.jpg");
            //final ImageIcon bgImage = CommonUtil.getDefaultBackgroundImage();
            if (bgImage != null) {
                progressAnimation.getContentPane().add(new JLabel(bgImage), 2);
            } else {
                progressAnimation.getContentPane().add(new JLabel(), 2);
            }

            switch (cardType) {
            case GZ_CARD:
                waitCommunicationTask(new GZReadCardTask(), progressAnimation);
                break;
            default:
                getLogger(InsertCardAction.class.getName()).log(Level.WARNING,
                        "Unsupported card type[{0}] for InsertCardAction", cardType.name());
                handleErr(getResourceMsg(GzCardConductor.GUOZHEN_CARD_OPERATION_PROMPT));
            }
        }
    });
}

From source file:com.limegroup.gnutella.gui.themes.setters.SubstanceThemeSetter.java

public void apply() {
    SubstanceLookAndFeel.setSkin(_skinClassName);
    ThemeMediator.applyCommonSkinUI();//from ww  w.j a  v  a  2 s . c o  m

    float scaledFontPolicyFactor = WINDOWS_SCALED_FONT_POLICY_FACTOR;
    if (OSUtils.isMacOSX()) {
        scaledFontPolicyFactor = MAC_SCALED_FONT_POLICY_FACTOR;
    } else if (OSUtils.isLinux()) {
        scaledFontPolicyFactor = LINUX_SCALED_FONT_POLICY_FACTOR;
    }

    if (LookUtils.IS_OS_WINDOWS) {
        fixWindowsOSFont();
    } else if (LookUtils.IS_OS_LINUX) {
        fixLinuxOSFont();
    }

    SubstanceLookAndFeel.setFontPolicy(SubstanceFontUtilities.getScaledFontPolicy(scaledFontPolicyFactor));

    //reduceFont("Label.font");
    //reduceFont("Table.font");
    //ResourceManager.setFontSizes(-1);
    //ResourceManager.setFontSizes(0);

    UIManager.put("Tree.leafIcon", UIManager.getIcon("Tree.closedIcon"));

    // remove split pane borders
    UIManager.put("SplitPane.border", BorderFactory.createEmptyBorder());

    if (!OSUtils.isMacOSX()) {
        UIManager.put("Table.focusRowHighlightBorder", UIManager.get("Table.focusCellHighlightBorder"));
    }

    UIManager.put("Table.focusCellHighlightBorder", BorderFactory.createEmptyBorder(1, 1, 1, 1));

    // Add a bold text version of simple text.
    Font normal = UIManager.getFont("Table.font");
    FontUIResource bold = new FontUIResource(normal.getName(), Font.BOLD, normal.getSize());
    UIManager.put("Table.font.bold", bold);
    UIManager.put("Tree.rowHeight", 0);
}

From source file:net.pms.newgui.LooksFrame.java

/**
 * Constructs a <code>DemoFrame</code>, configures the UI,
 * and builds the content./*from  w w w .  j  a v a  2s  .  com*/
 */
public LooksFrame(AutoUpdater autoUpdater, @Nonnull PmsConfiguration configuration,
        @Nonnull WindowPropertiesConfiguration windowConfiguration) {
    super(windowConfiguration.getGraphicsConfiguration());
    if (configuration == null) {
        throw new IllegalArgumentException("configuration can't be null");
    }
    setResizable(true);
    windowProperties = new WindowProperties(this, STANDARD_SIZE, MINIMUM_SIZE, windowConfiguration);
    this.autoUpdater = autoUpdater;
    this.configuration = configuration;
    assert this.configuration != null;
    setMinimumSize(MINIMUM_SIZE);
    Options.setDefaultIconSize(new Dimension(18, 18));
    Options.setUseNarrowButtons(true);

    // Set view level, can be omitted if ViewLevel is implemented in configuration
    // by setting the view level as variable initialization
    if (configuration.isHideAdvancedOptions()) {
        viewLevel = ViewLevel.NORMAL;
    } else {
        viewLevel = ViewLevel.ADVANCED;
    }

    // Global options
    Options.setTabIconsEnabled(true);
    UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, null);

    // Swing Settings
    initializeLookAndFeel();

    // wait till the look and feel has been initialized before (possibly) displaying the update notification dialog
    if (autoUpdater != null) {
        autoUpdater.addObserver(this);
        autoUpdater.pollServer();
    }

    // Shared Fonts
    final Integer twelve = Integer.valueOf(12);
    final Integer fontPlain = Integer.valueOf(Font.PLAIN);
    final Integer fontBold = Integer.valueOf(Font.BOLD);

    LazyValue dialogPlain12 = new LazyValue() {
        @Override
        public Object createValue(UIDefaults t) {
            return new FontUIResource(Font.DIALOG, fontPlain, twelve);
        }
    };

    LazyValue sansSerifPlain12 = new LazyValue() {
        @Override
        public Object createValue(UIDefaults t) {
            return new FontUIResource(Font.SANS_SERIF, fontPlain, twelve);
        }
    };

    LazyValue monospacedPlain12 = new LazyValue() {
        @Override
        public Object createValue(UIDefaults t) {
            return new FontUIResource(Font.MONOSPACED, fontPlain, twelve);
        }
    };

    LazyValue dialogBold12 = new LazyValue() {
        @Override
        public Object createValue(UIDefaults t) {
            return new FontUIResource(Font.DIALOG, fontBold, twelve);
        }
    };

    Object MenuFont = dialogPlain12;
    Object FixedControlFont = monospacedPlain12;
    Object ControlFont = dialogPlain12;
    Object MessageFont = dialogPlain12;
    Object WindowFont = dialogBold12;
    Object ToolTipFont = sansSerifPlain12;
    Object IconFont = ControlFont;

    // Override our fonts with a unicode font for languages with special characters
    final String language = configuration.getLanguageTag();
    if (language != null && (language.equals("ja") || language.startsWith("zh") || language.equals("ko"))) {
        // http://propedit.sourceforge.jp/propertieseditor.jnlp
        MenuFont = sansSerifPlain12;
        FixedControlFont = sansSerifPlain12;
        ControlFont = sansSerifPlain12;
        MessageFont = sansSerifPlain12;
        WindowFont = sansSerifPlain12;
        IconFont = sansSerifPlain12;
    }

    UIManager.put("Button.font", ControlFont);
    UIManager.put("CheckBox.font", ControlFont);
    UIManager.put("CheckBoxMenuItem.font", MenuFont);
    UIManager.put("ComboBox.font", ControlFont);
    UIManager.put("EditorPane.font", ControlFont);
    UIManager.put("FileChooser.listFont", IconFont);
    UIManager.put("FormattedTextField.font", ControlFont);
    UIManager.put("InternalFrame.titleFont", WindowFont);
    UIManager.put("Label.font", ControlFont);
    UIManager.put("List.font", ControlFont);
    UIManager.put("PopupMenu.font", MenuFont);
    UIManager.put("Menu.font", MenuFont);
    UIManager.put("MenuBar.font", MenuFont);
    UIManager.put("MenuItem.font", MenuFont);
    UIManager.put("MenuItem.acceleratorFont", MenuFont);
    UIManager.put("RadioButton.font", ControlFont);
    UIManager.put("RadioButtonMenuItem.font", MenuFont);
    UIManager.put("OptionPane.font", MessageFont);
    UIManager.put("OptionPane.messageFont", MessageFont);
    UIManager.put("OptionPane.buttonFont", MessageFont);
    UIManager.put("Panel.font", ControlFont);
    UIManager.put("PasswordField.font", ControlFont);
    UIManager.put("ProgressBar.font", ControlFont);
    UIManager.put("ScrollPane.font", ControlFont);
    UIManager.put("Slider.font", ControlFont);
    UIManager.put("Spinner.font", ControlFont);
    UIManager.put("TabbedPane.font", ControlFont);
    UIManager.put("Table.font", ControlFont);
    UIManager.put("TableHeader.font", ControlFont);
    UIManager.put("TextArea.font", FixedControlFont);
    UIManager.put("TextField.font", ControlFont);
    UIManager.put("TextPane.font", ControlFont);
    UIManager.put("TitledBorder.font", ControlFont);
    UIManager.put("ToggleButton.font", ControlFont);
    UIManager.put("ToolBar.font", MenuFont);
    UIManager.put("ToolTip.font", ToolTipFont);
    UIManager.put("Tree.font", ControlFont);
    UIManager.put("Viewport.font", ControlFont);

    setTitle("Test");
    setIconImage(readImageIcon("icon-32.png").getImage());

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JComponent jp = buildContent();
    String showScrollbars = System.getProperty("scrollbars", "").toLowerCase();

    /**
     * Handle scrollbars:
     *
     * 1) forced scrollbars (-Dscrollbars=true): always display them
     * 2) optional scrollbars (-Dscrollbars=optional): display them as needed
     * 3) otherwise (default): don't display them
     */
    switch (showScrollbars) {
    case "true":
        setContentPane(new JScrollPane(jp, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS));
        break;
    case "optional":
        setContentPane(new JScrollPane(jp, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
        break;
    default:
        setContentPane(jp);
        break;
    }

    String projectName = PropertiesUtil.getProjectProperties().get("project.name");
    String projectVersion = PropertiesUtil.getProjectProperties().get("project.version");
    String title = projectName + " " + projectVersion;

    // If the version contains a "-" (e.g. "1.50.1-SNAPSHOT" or "1.50.1-beta1"), add a warning message
    if (projectVersion.indexOf('-') > -1) {
        title = title + " - " + Messages.getString("LooksFrame.26");
    }

    if (PMS.getTraceMode() == 2) {
        // Forced trace mode
        title = title + "  [" + Messages.getString("TracesTab.10").toUpperCase() + "]";
    }

    setTitle(title);
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

    // Display tooltips immediately and for a long time
    ToolTipManager.sharedInstance().setInitialDelay(400);
    ToolTipManager.sharedInstance().setDismissDelay(60000);
    ToolTipManager.sharedInstance().setReshowDelay(400);

    if (!configuration.isMinimized() && System.getProperty(START_SERVICE) == null) {
        setVisible(true);
    }
    BasicSystemUtils.INSTANCE.addSystemTray(this);
}

From source file:net.sf.jabref.JabRefGUI.java

private void setLookAndFeel() {
    try {/*from ww  w  .  j  av  a 2 s. co  m*/
        String lookFeel;
        String systemLookFeel = UIManager.getSystemLookAndFeelClassName();

        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // FIXME: Problems with OpenJDK and GTK L&F
            // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
            if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
                // Metal L&F
                lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
                LOGGER.warn(
                        "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
            } else {
                lookFeel = systemLookFeel;
            }
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }

        // FIXME: Open JDK problem
        if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
                && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
            // try to avoid ending up with the ugly Metal L&F
            Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel();
            Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer());
            com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
            UIManager.setLookAndFeel(lnf);
        } else {
            try {
                UIManager.setLookAndFeel(lookFeel);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                    | UnsupportedLookAndFeelException e) {
                // specified look and feel does not exist on the classpath, so use system l&f
                UIManager.setLookAndFeel(systemLookFeel);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
                // notify the user
                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
                        Localization.lang(
                                "Unable to find the requested look and feel and thus the default one is used."),
                        Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
                LOGGER.warn("Unable to find requested look and feel", e);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Look and feel could not be set", e);
    }

    // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
    boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
    if (overrideDefaultFonts) {
        int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
        UIDefaults defaults = UIManager.getDefaults();
        Enumeration<Object> keys = defaults.keys();
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
    }
}