Example usage for javax.swing LookAndFeel getClass

List of usage examples for javax.swing LookAndFeel getClass

Introduction

In this page you can find the example usage for javax.swing LookAndFeel getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java

/**
 * Creates {@link EmbeddedSwingComposite} with some Swing components to show it using different
 * LAFs.//ww w .  ja  v  a 2s.c  om
 */
private void createPreviewArea(Group previewGroup) {
    try {
        LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
        EmbeddedSwingComposite awtComposite = new EmbeddedSwingComposite(previewGroup, SWT.NONE) {
            @Override
            protected JComponent createSwingComponent() {
                // create the JRootPane
                JRootPane rootPane = new JRootPane();
                {
                    JMenuBar menuBar = new JMenuBar();
                    rootPane.setJMenuBar(menuBar);
                    {
                        JMenu mnFile = new JMenu(Messages.LafPreferencePage_previewFile);
                        menuBar.add(mnFile);
                        {
                            JMenuItem mntmNew = new JMenuItem(Messages.LafPreferencePage_previewNew);
                            mnFile.add(mntmNew);
                        }
                        {
                            JMenuItem mntmExit = new JMenuItem(Messages.LafPreferencePage_previewExit);
                            mnFile.add(mntmExit);
                        }
                    }
                    {
                        JMenu mnView = new JMenu(Messages.LafPreferencePage_previewView);
                        menuBar.add(mnView);
                        {
                            JMenuItem mntmCommon = new JMenuItem(Messages.LafPreferencePage_previewCommon);
                            mnView.add(mntmCommon);
                        }
                    }
                }
                GridBagLayout gridBagLayout = new GridBagLayout();
                gridBagLayout.columnWidths = new int[] { 0, 0, 0 };
                gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 };
                gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0E-4 };
                gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0E-4 };
                rootPane.getContentPane().setLayout(gridBagLayout);
                {
                    JLabel lblLabel = new JLabel(Messages.LafPreferencePage_previewLabel);
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.insets = new Insets(0, 0, 5, 5);
                    gbc.gridx = 0;
                    gbc.gridy = 0;
                    rootPane.getContentPane().add(lblLabel, gbc);
                }
                {
                    JButton btnPushButton = new JButton(Messages.LafPreferencePage_previewButton);
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.insets = new Insets(0, 0, 5, 0);
                    gbc.gridx = 1;
                    gbc.gridy = 0;
                    rootPane.getContentPane().add(btnPushButton, gbc);
                }
                {
                    JComboBox comboBox = new JComboBox();
                    comboBox.setModel(new DefaultComboBoxModel(new String[] {
                            Messages.LafPreferencePage_previewCombo, "ComboBox Item 1", "ComboBox Item 2" }));
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.insets = new Insets(0, 0, 5, 5);
                    gbc.fill = GridBagConstraints.HORIZONTAL;
                    gbc.gridx = 0;
                    gbc.gridy = 1;
                    rootPane.getContentPane().add(comboBox, gbc);
                }
                {
                    JRadioButton rdbtnRadioButton = new JRadioButton(Messages.LafPreferencePage_previewRadio);
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.insets = new Insets(0, 0, 5, 0);
                    gbc.gridx = 1;
                    gbc.gridy = 1;
                    rootPane.getContentPane().add(rdbtnRadioButton, gbc);
                }
                {
                    JCheckBox chckbxCheckbox = new JCheckBox(Messages.LafPreferencePage_previewCheck);
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.insets = new Insets(0, 0, 0, 5);
                    gbc.gridx = 0;
                    gbc.gridy = 2;
                    rootPane.getContentPane().add(chckbxCheckbox, gbc);
                }
                {
                    JTextField textField = new JTextField();
                    textField.setText(Messages.LafPreferencePage_previewTextField);
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.fill = GridBagConstraints.HORIZONTAL;
                    gbc.gridx = 1;
                    gbc.gridy = 2;
                    rootPane.getContentPane().add(textField, gbc);
                }
                return rootPane;
            }
        };
        awtComposite.populate();
        // restore current laf
        UIManager.put("ClassLoader", currentLookAndFeel.getClass().getClassLoader());
        UIManager.setLookAndFeel(currentLookAndFeel);
    } catch (Throwable e) {
        DesignerPlugin.log(e);
    }
}

From source file:org.yccheok.jstock.gui.JStock.java

public void createLookAndFeelMenuItems() {
    LookAndFeel currentlaf = UIManager.getLookAndFeel();

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

    for (int i = 0; i < lafInfo.length; i++) {
        JMenuItem mi = (JRadioButtonMenuItem) jMenu4.add(new JRadioButtonMenuItem(lafInfo[i].getName()));
        buttonGroup1.add(mi);//from   ww w. j  a v a2s.  c  om
        mi.addActionListener(new ChangeLookAndFeelAction(this, lafInfo[i].getClassName()));

        if (currentlaf != null) {
            if (lafInfo[i].getClassName().equals(currentlaf.getClass().getName())) {
                ((JRadioButtonMenuItem) mi).setSelected(true);
            }
        }
    }

    // Always on Top
    jMenu4.addSeparator();
    this.alwaysOnTopMenuItem = jMenu4.add(new JCheckBoxMenuItem(GUIBundle.getString("MainFrame_AlwaysOnTop")));

    this.alwaysOnTopMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AbstractButton aButton = (AbstractButton) e.getSource();
            boolean selected = aButton.getModel().isSelected();

            JStock.this._setAlwaysOnTop(selected);
        }
    });
}

From source file:org.yccheok.jstock.gui.MainFrame.java

public void createLookAndFeelMenuItem() {
    LookAndFeel currentlaf = UIManager.getLookAndFeel();

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

    for (int i = 0; i < lafInfo.length; i++) {
        JMenuItem mi = (JRadioButtonMenuItem) jMenu4.add(new JRadioButtonMenuItem(lafInfo[i].getName()));
        buttonGroup1.add(mi);// www .j  ava 2 s. com
        mi.addActionListener(new ChangeLookAndFeelAction(this, lafInfo[i].getClassName()));

        if (currentlaf != null) {
            if (lafInfo[i].getClassName().equals(currentlaf.getClass().getName())) {
                ((JRadioButtonMenuItem) mi).setSelected(true);
            }
        }
    }
}

From source file:org.zaproxy.zap.utils.ZapSupportUtils.java

public static String getLookAndFeel() {
    LookAndFeel laf = UIManager.getLookAndFeel();
    String strLaf;//from  ww w  .  j a v  a2s.  c o  m
    if (laf != null) {
        strLaf = laf.getName() + " (" + laf.getClass().getCanonicalName() + ")";
    } else {
        strLaf = "[null]";
    }
    return Constant.messages.getString("support.laf.label") + " " + strLaf;
}

From source file:phex.gui.common.GUIRegistry.java

private void initializeGUISettings(DGuiSettings guiSettings) {
    // set default values...
    if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS) {
        showTableHorizontalLines = false;
        showTableVerticalLines = false;//  w w  w  .  j a va 2  s.c o  m
    } else {
        showTableHorizontalLines = true;
        showTableVerticalLines = true;
    }
    useLogBandwidthSlider = false;
    showRespectCopyrightNotice = true;

    // sets old values from old cfg...
    ToolTipManager.sharedInstance().setEnabled(InterfacePrefs.DisplayTooltip.get().booleanValue());

    String userLafClass;
    String iconPackName;
    // load values from gui new settings if available.
    if (guiSettings != null) {
        if (guiSettings.isSetLogBandwidthSliderUsed()) {
            useLogBandwidthSlider = guiSettings.isLogBandwidthSliderUsed();
        }
        if (guiSettings.isSetShowRespectCopyrightNotice()) {
            showRespectCopyrightNotice = guiSettings.isShowRespectCopyrightNotice();
        }

        DTableList tableList = guiSettings.getTableList();
        if (tableList != null && tableList.isSetShowHorizontalLines()) {
            showTableHorizontalLines = tableList.isShowHorizontalLines();
        }
        if (tableList != null && tableList.isSetShowVerticalLines()) {
            showTableVerticalLines = tableList.isShowVerticalLines();
        }
        iconPackName = guiSettings.getIconPackName();
        userLafClass = guiSettings.getLookAndFeelClass();
    } else {
        userLafClass = null;
        iconPackName = null;
    }

    if (iconPackName != null) {
        plafIconPack = IconPack.createIconPack(iconPackName);
    }
    if (plafIconPack == null) {
        plafIconPack = IconPack.createDefaultIconPack();
    }

    LookAndFeel laf = LookAndFeelUtils.determineLAF(userLafClass);
    String phexLafClass = laf.getClass().getName();
    if (userLafClass != null && !phexLafClass.equals(userLafClass)) {// in case we had to switch LAF show error.
        JOptionPane.showMessageDialog(GUIRegistry.getInstance().getMainFrame(),
                Localizer.getString("LAF_ErrorLoadingSwitchToDefault"), Localizer.getString("Error"),
                JOptionPane.ERROR_MESSAGE);
    }

    if (phexLafClass.equals(UIManager.getLookAndFeel().getClass().getName())) {
        // in case correct laf is already set just update UI!
        // this must be done to get colors correctly initialized!
        GUIUtils.updateComponentsUI();
    } else {
        try {
            LookAndFeelUtils.setLookAndFeel(laf);
        } catch (ExceptionInInitializerError ex) {
            // headless mode
        } catch (LookAndFeelFailedException e) {// this is supposed to never happen.. since the LAF
                                                // should already be tested to function.
            assert (false);
        }
    }
}