Example usage for javax.swing UIManager get

List of usage examples for javax.swing UIManager get

Introduction

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

Prototype

public static Object get(Object key) 

Source Link

Document

Returns an object from the defaults.

Usage

From source file:Main.java

/**
 * Sets the default UI font style.//from ww  w .  j av a 2 s  .c o  m
 * 
 * @param fontStyle
 *            The font style
 * @see Font See Font Javadoc for possible styles
 */
public static void setUIFontStyle(final int fontStyle) {
    for (Enumeration<?> en = UIManager.getDefaults().keys(); en.hasMoreElements();) {
        Object key = en.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            FontUIResource fontRes = (FontUIResource) value;
            UIManager.put(key, new ProxyLazyValue("javax.swing.plaf.FontUIResource", null,
                    new Object[] { fontRes.getName(), fontStyle, fontRes.getSize() }));
        }
    }
}

From source file:Main.java

/** 
 * Adjust all fonts for displaying to the given size.
 * <br>Use with care!//from   ww  w.j a  va  2 s.c om
 */
public static void setUIFontSize(final int size) {

    final java.util.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 = ifont.deriveFont((float) size);
            UIManager.put(key, ofont);
        }
    }
}

From source file:Main.java

public void paint(Graphics g) {
    String input = "this is a test.this is a test.this is a test.this is a test.";

    AttributedString attributedString = new AttributedString(input);
    attributedString.addAttribute(TextAttribute.FONT, (Font) UIManager.get("Label.font"));
    Color color = (Color) UIManager.get("Label.foreground");

    attributedString.addAttribute(TextAttribute.FOREGROUND, color);

    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    int width = getSize().width;
    int x = 10;//w  w w.  ja va  2s  .  c o  m
    int y = 30;

    AttributedCharacterIterator characterIterator = attributedString.getIterator();
    FontRenderContext fontRenderContext = g2d.getFontRenderContext();
    LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, fontRenderContext);
    while (measurer.getPosition() < characterIterator.getEndIndex()) {
        TextLayout textLayout = measurer.nextLayout(width);
        y += textLayout.getAscent();
        textLayout.draw(g2d, x, y);
        y += textLayout.getDescent() + textLayout.getLeading();
    }
}

From source file:Main.java

public Main() {
    super(BoxLayout.Y_AXIS);
    try {//from   w w w.  j  a v  a2s.  c  om
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                System.out.println("set");
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Object o = UIManager.get("TextArea[Enabled+NotInScrollPane].borderPainter");

    UIDefaults paneDefaults = new UIDefaults();
    paneDefaults.put("TextPane.borderPainter", o);

    JTextPane pane = new JTextPane();
    pane.setMargin(new Insets(10, 10, 10, 10));

    pane.putClientProperty("Nimbus.Overrides", paneDefaults);
    pane.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
    pane.setText("this \nis \na \ntest\n");
    add(pane);

}

From source file:com.willwinder.universalgcodesender.MainWindow.java

/**
 * @param args the command line arguments
 *//*from ww  w .  j a  va  2 s.  c  o  m*/
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(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.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 MainWindow mw = new MainWindow(backend);

    /* Apply the settings to the MainWindow bofore showing it */
    mw.arrowMovementEnabled.setSelected(mw.settings.isManualModeEnabled());
    mw.stepSizeSpinner.setValue(mw.settings.getManualModeStepSize());
    boolean unitsAreMM = mw.settings.getDefaultUnits().equals("mm");
    mw.mmRadioButton.setSelected(unitsAreMM);
    mw.inchRadioButton.setSelected(!unitsAreMM);
    mw.fileChooser = new JFileChooser(mw.settings.getLastOpenedFilename());
    mw.commPortComboBox.setSelectedItem(mw.settings.getPort());
    mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate());
    mw.scrollWindowCheckBox.setSelected(mw.settings.isScrollWindowEnabled());
    mw.showVerboseOutputCheckBox.setSelected(mw.settings.isVerboseOutputEnabled());
    mw.showCommandTableCheckBox.setSelected(mw.settings.isCommandTableEnabled());
    mw.showCommandTableCheckBoxActionPerformed(null);
    mw.firmwareComboBox.setSelectedItem(mw.settings.getFirmwareVersion());

    mw.setSize(mw.settings.getMainWindowSettings().width, mw.settings.getMainWindowSettings().height);
    mw.setLocation(mw.settings.getMainWindowSettings().xLocation,
            mw.settings.getMainWindowSettings().yLocation);

    mw.addComponentListener(new ComponentListener() {
        @Override
        public void componentResized(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().height = ce.getComponent().getSize().height;
            mw.settings.getMainWindowSettings().width = ce.getComponent().getSize().width;
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
            mw.settings.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);
        }
    });

    mw.initFileChooser();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            if (mw.fileChooser.getSelectedFile() != null) {
                mw.settings.setLastOpenedFilename(mw.fileChooser.getSelectedFile().getAbsolutePath());
            }

            mw.settings.setDefaultUnits(mw.inchRadioButton.isSelected() ? "inch" : "mm");
            mw.settings.setManualModeStepSize(mw.getStepSize());
            mw.settings.setManualModeEnabled(mw.arrowMovementEnabled.isSelected());
            mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString());
            mw.settings.setPortRate(mw.baudrateSelectionComboBox.getSelectedItem().toString());
            mw.settings.setScrollWindowEnabled(mw.scrollWindowCheckBox.isSelected());
            mw.settings.setVerboseOutputEnabled(mw.showVerboseOutputCheckBox.isSelected());
            mw.settings.setCommandTableEnabled(mw.showCommandTableCheckBox.isSelected());
            mw.settings.setFirmwareVersion(mw.firmwareComboBox.getSelectedItem().toString());
            SettingsFactory.saveSettings(mw.settings);

            if (mw.pendantUI != null) {
                mw.pendantUI.stop();
            }
        }
    });

    // Check command line for a file to open.
    boolean open = false;
    for (String arg : args) {
        if (open) {
            try {
                backend.setGcodeFile(new File(arg));
            } catch (Exception ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            }
        }
        if (arg.equals("--open") || arg.equals("-o")) {
            open = true;
        }
    }
}

From source file:Main.java

/**
 * Workaround for Bug#5063999.//w w  w.j  a va 2s .  c  om
 */
public static void installDefaults() {
    String defaultlaf = System.getProperty("swing.defaultlaf");
    if (defaultlaf == null || defaultlaf.length() == 0) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException
                | InstantiationException ex) {
            // NO-OP
        }
    }
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    UIManager.put(FORMATTED_TEXTFIELD_FONT_KEY, UIManager.get(TEXTFIELD_FONT_KEY));
    UIManager.put(FORMATTED_TEXTFIELD_INACTIVE_BACKGROUND_KEY,
            UIManager.get(TEXTFIELD_INACTIVE_BACKGROUND_KEY));
    UIManager.put(PASSWORDFIELD_FONT_KEY, UIManager.get(TEXTFIELD_FONT_KEY));
    //    try {
    //      UIManager.put(LafWidget.TABBED_PANE_PREVIEW_PAINTER,
    //          new DefaultTabPreviewPainter() {
    //
    //            /**
    //             * {@inheritDoc}
    //             */
    //            @Override
    //            public TabOverviewKind getOverviewKind(JTabbedPane tabPane) {
    //              return TabOverviewKind.ROUND_CAROUSEL;
    //              // return TabOverviewKind.MENU_CAROUSEL;
    //            }
    //          });
    //      UIManager.put(LafWidget.COMPONENT_PREVIEW_PAINTER,
    //          new DefaultPreviewPainter());
    //      UIManager.put(LafWidget.TEXT_EDIT_CONTEXT_MENU, Boolean.TRUE);
    //      // UIManager.put(LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE);
    //    } catch (Throwable ignored) {
    //      // substance may not be available.
    //    }
}

From source file:CheckBoxNodeTreeSample.java

public CheckBoxNodeRenderer() {
    Font fontValue;/*from   w ww . j  a v  a2 s  . com*/
    fontValue = UIManager.getFont("Tree.font");
    if (fontValue != null) {
        leafRenderer.setFont(fontValue);
    }
    Boolean booleanValue = (Boolean) UIManager.get("Tree.drawsFocusBorderAroundIcon");
    leafRenderer.setFocusPainted((booleanValue != null) && (booleanValue.booleanValue()));

    selectionBorderColor = UIManager.getColor("Tree.selectionBorderColor");
    selectionForeground = UIManager.getColor("Tree.selectionForeground");
    selectionBackground = UIManager.getColor("Tree.selectionBackground");
    textForeground = UIManager.getColor("Tree.textForeground");
    textBackground = UIManager.getColor("Tree.textBackground");
}

From source file:es.emergya.cliente.Mobile.java

@Override
protected void configureUI() {
    UIManager.put("swing.boldMetal", Boolean.FALSE); //$NON-NLS-1$

    UIManager.put("TabbedPane.selected", Color.decode("#B1BEF0"));
    final Enumeration<Object> 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, getLightFont());
        }/*from  www. j a  v a  2 s. c  o  m*/

    }
    UIManager.put("TableHeader.font", deriveBoldFont(10f));
    UIManager.put("TabbedPane.font", deriveLightFont(9f));
}

From source file:com.mirth.connect.plugins.imageviewer.ImageViewer.java

public void viewAttachments(String channelId, Long messageId, String attachmentId) {

    JFrame frame = new JFrame("Image Viewer");

    try {/*from  w w  w .  ja v  a 2  s.c  om*/

        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] rawData = attachment.getContent();
        ByteArrayInputStream bis = new ByteArrayInputStream(rawData);

        image = ImageIO.read(new Base64InputStream(bis));

        JScrollPane pictureScrollPane = new JScrollPane(new JLabel(new ImageIcon(image)));
        pictureScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        pictureScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        frame.add(pictureScrollPane);

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.pack();

        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();

        // Resize the frame so that it fits and scrolls images larger than
        // 800x600 properly.
        if (imageWidth > 800 || imageHeight > 600) {
            int width = imageWidth;
            int height = imageHeight;
            if (imageWidth > 800) {
                width = 800;
            }
            if (imageHeight > 600) {
                height = 600;
            }

            // Also add the scrollbars to the window width if necessary.
            Integer scrollBarWidth = (Integer) UIManager.get("ScrollBar.width");
            int verticalScrollBar = 0;
            int horizontalScrollBar = 0;

            if (width == 800) {
                horizontalScrollBar = scrollBarWidth.intValue();
            }
            if (height == 600) {
                verticalScrollBar = scrollBarWidth.intValue();
            }

            // Also add the window borders to the width.
            width = width + frame.getInsets().left + frame.getInsets().right + verticalScrollBar;
            height = height + frame.getInsets().top + frame.getInsets().bottom + horizontalScrollBar;

            frame.setSize(width, height);
        }

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:UndoDrawing.java

public static Action getUndoAction(UndoManager manager) {
    return new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText"));
}