Example usage for javax.swing UIManager getDefaults

List of usage examples for javax.swing UIManager getDefaults

Introduction

In this page you can find the example usage for javax.swing UIManager getDefaults.

Prototype

public static UIDefaults getDefaults() 

Source Link

Document

Returns the defaults.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Icon Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon icon = new ImageIcon("logo.gif");
    UIDefaults defaults = UIManager.getDefaults();
    defaults.put("Slider.horizontalThumbIcon", icon);
    JSlider aJSlider = new JSlider();
    aJSlider.setPaintTicks(true);/*from w w  w. j  ava2s  . c o m*/
    frame.add(aJSlider, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // No Ticks//ww  w  .ja va 2  s.  com
    JSlider jSliderOne = new JSlider();
    Icon icon = new ImageIcon("yourFile.gif");
    UIDefaults defaults = UIManager.getDefaults();
    defaults.put("Slider.horizontalThumbIcon", icon);

    frame.add(jSliderOne, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ListProperties.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("List Properties");

    final CustomTableModel model = new CustomTableModel();
    model.uiDefaultsUpdate(UIManager.getDefaults());
    TableSorter sorter = new TableSorter(model);

    JTable table = new JTable(sorter);
    TableHeaderSorter.install(sorter, table);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    Container content = frame.getContentPane();

    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 400);/*from  w w w.  ja v  a2 s .c om*/
    frame.setVisible(true);
}

From source file:ListProperties.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("List Properties");

    final CustomTableModel model = new CustomTableModel();
    model.uiDefaultsUpdate(UIManager.getDefaults());
    TableSorter sorter = new TableSorter(model);

    JTable table = new JTable(sorter);
    TableHeaderSorter.install(sorter, table);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final String lafClassName = actionEvent.getActionCommand();
            Runnable runnable = new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel(lafClassName);
                        SwingUtilities.updateComponentTreeUI(frame);
                        // Added
                        model.uiDefaultsUpdate(UIManager.getDefaults());
                    } catch (Exception exception) {
                        JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                                JOptionPane.ERROR_MESSAGE);
                    }/*  w  w  w .j a  va 2  s .  co m*/
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    };

    JToolBar toolbar = new JToolBar();
    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        toolbar.add(button);
    }

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
}

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));

        }//from  w w  w .j  ava2 s.c  o  m

    }

}

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 av a  2s  .  c om
    }
}

From source file:Main.java

public static void setUIFont(Font f) {
    ///*from   w ww. j  av  a  2s. c o  m*/
    // 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) {
    //// w w  w.ja  v a  2 s.co 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

/**
 * Code from http://stackoverflow.com/questions/1236231/managing-swing-ui-default-font-sizes-without-quaqua
 * @param fontSize//from  w  w  w  .ja  va 2s.  c  o  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

/**
 * magnify the all fonts in swing.//  ww  w  .j av a2 s  .  c o  m
 * 
 * @param mag
 *            magnify parameter <br/> mag > 1. : large <br/> mag < 1. :
 *            small
 */
public static void magnifyAllFont(float mag) {
    List history = new LinkedList();
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration it = defaults.keys();
    while (it.hasMoreElements()) {
        Object key = it.nextElement();
        Object a = defaults.get(key);
        if (a instanceof Font) {
            if (history.contains(a))
                continue;
            Font font = (Font) a;
            font = font.deriveFont(font.getSize2D() * mag);
            defaults.put(key, font);
            history.add(font);
        }
    }
}