Java Code Examples for javax.swing.SwingUtilities#updateComponentTreeUI()

The following examples show how to use javax.swing.SwingUtilities#updateComponentTreeUI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Switches the current theme.
 */
private void switchTheme() {
	boolean currentDark = DrMIPS.prefs.getBoolean(DrMIPS.DARK_THEME_PREF, DrMIPS.DEFAULT_DARK_THEME);
	boolean dark = mnuSwitchTheme.isSelected();
	if(dark && !currentDark)
		Util.setDarkLookAndFeel();
	else if(!dark && currentDark)
		Util.setLightLookAndFeel();

	DrMIPS.prefs.putBoolean(DrMIPS.DARK_THEME_PREF, dark);
	SwingUtilities.updateComponentTreeUI(this);
	if(dlgFindReplace != null) SwingUtilities.updateComponentTreeUI(dlgFindReplace);
	if(dlgSupportedInstructions != null) SwingUtilities.updateComponentTreeUI(dlgSupportedInstructions);
	if(dlgStatistics != null) SwingUtilities.updateComponentTreeUI(dlgStatistics);
	if(cpuFileChooser != null) cpuFileChooser.updateUI();
	if(codeFileChooser != null) codeFileChooser.updateUI();
	datapath.setCPU(cpu);
	datapath.setControlPathVisible(mnuControlPath.isSelected());
	datapath.setShowArrows(mnuArrowsInWires.isSelected());
	datapath.setPerformanceMode(mnuPerformanceMode.isSelected());
	refreshDatapathHelp();
	txtCode.setColors();
}
 
Example 2
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Switches to use tabs.
 */
private void switchToTabs() {
	saveFrameBounds("code", frmCode);
	saveFrameBounds("assembled_code", frmAssembledCode);
	saveFrameBounds("datapath", frmDatapath);
	saveFrameBounds("registers", frmRegisters);
	saveFrameBounds("data_memory", frmDataMemory);

	remove(desktop);
	add(pnlSplit, BorderLayout.CENTER);
	refreshTabSides();

	desktop.remove(frmCode);
	desktop.remove(frmAssembledCode);
	desktop.remove(frmDatapath);
	desktop.remove(frmRegisters);
	desktop.remove(frmDataMemory);

	mnuWindows.setEnabled(false);
	SwingUtilities.updateComponentTreeUI(this);
	txtCode.requestFocus(); // make sure a component has focus so shortcut keys work
}
 
Example 3
Source File: ControlWindow.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
static public void setLookAndFeel() {
	try {
		if (ij.IJ.isLinux()) {
			// Nimbus looks great but it's unstable: after a while, swing components stop repainting, throwing all sort of exceptions.
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
			for (final Frame frame : Frame.getFrames()) {
				if (frame.isEnabled()) SwingUtilities.updateComponentTreeUI(frame);
			}
			// all done above
			//if (null != frame) SwingUtilities.updateComponentTreeUI(frame);
			//if (null != IJ.getInstance()) javax.swing.SwingUtilities.updateComponentTreeUI(IJ.getInstance());
			//Display.updateComponentTreeUI();
		}
	} catch (ClassNotFoundException cnfe) {
		Utils.log2("Could not find Nimbus L&F");
	} catch (Exception e) {
		IJError.print(e);
	}
}
 
Example 4
Source File: Test6199676.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 5
Source File: Test6981576.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    if (this.infos == null) {
        this.infos = UIManager.getInstalledLookAndFeels();
        Thread.currentThread().setUncaughtExceptionHandler(this);
        JPanel panel = new JPanel();
        panel.setBorder(this);
        this.frame = new JFrame(getClass().getSimpleName());
        this.frame.add(panel);
        this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.frame.setVisible(true);
    }
    if (this.index == this.infos.length) {
        this.frame.dispose();
    }
    else {
        LookAndFeelInfo info = this.infos[this.index % this.infos.length];
        try {
            UIManager.setLookAndFeel(info.getClassName());
        }
        catch (Exception exception) {
            System.err.println("could not change look and feel");
        }
        SwingUtilities.updateComponentTreeUI(this.frame);
        this.frame.pack();
        this.frame.setLocationRelativeTo(null);
        this.index++;
        SwingUtilities.invokeLater(this);
    }
}
 
Example 6
Source File: JCEditor.java    From JCEditor with GNU General Public License v2.0 5 votes vote down vote up
/**
* Método que atualiza o LAF utilizando o método updateComponentTreeUI, da classe SwingUtilities
* Este método também retira a borda da barra de menu e do JTextArea
*/
private void atualizarLAF() {
	SwingUtilities.updateComponentTreeUI(this);
	barraDeMenu.setBorder(null);
	painelSeparador.setBorder(null);
	scrollPane.setBorder(null);

	for (AreaDeTexto adt : lista) {
		adt.setBorder(null);
		adt.barraDeRolagem().setBorder(null);
		SwingUtilities.updateComponentTreeUI(adt.fileChooser());
	}
}
 
Example 7
Source File: ColorCustomizationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void check(Color c) {
    SwingUtilities.updateComponentTreeUI(label);
    label.paint(g);
    if (label.getBackground().getRGB() != c.getRGB()) {
        System.err.println("Color mismatch!");
        System.err.println("   found: " + label.getBackground());
        System.err.println("   expected: " + c);
        throw new RuntimeException("Test failed");
    }
}
 
Example 8
Source File: Test6981576.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    if (this.infos == null) {
        this.infos = UIManager.getInstalledLookAndFeels();
        Thread.currentThread().setUncaughtExceptionHandler(this);
        JPanel panel = new JPanel();
        panel.setBorder(this);
        this.frame = new JFrame(getClass().getSimpleName());
        this.frame.add(panel);
        this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.frame.setVisible(true);
    }
    if (this.index == this.infos.length) {
        this.frame.dispose();
    }
    else {
        LookAndFeelInfo info = this.infos[this.index % this.infos.length];
        try {
            UIManager.setLookAndFeel(info.getClassName());
        }
        catch (Exception exception) {
            System.err.println("could not change look and feel");
        }
        SwingUtilities.updateComponentTreeUI(this.frame);
        this.frame.pack();
        this.frame.setLocationRelativeTo(null);
        this.index++;
        SwingUtilities.invokeLater(this);
    }
}
 
Example 9
Source File: Test6199676.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 10
Source File: TranslucentShapedFrameTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates new form TranslucentShapedFrameTest
 */
public TranslucentShapedFrameTest() {
    // not necessary, but we just look nicer
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {}

    initComponents();
    checkEffects();

    SwingUtilities.updateComponentTreeUI(this);
}
 
Example 11
Source File: Test6199676.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 12
Source File: BooleanTableCellRenderer.java    From burp-flow with MIT License 5 votes vote down vote up
private void initialize() {
    setOpaque(true);
    putClientProperty("JComponent.sizeVariant", "small");
    SwingUtilities.updateComponentTreeUI(this);
    setLayout(new GridBagLayout());
    setMargin(new Insets(0, 0, 0, 0));
    setHorizontalAlignment(JLabel.CENTER);
    setBorderPainted(true);
}
 
Example 13
Source File: Test6199676.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
Example 14
Source File: FPortecle.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Display the options dialog and store the user's choices.
 */
private void showOptions()
{
	DOptions dOptions = new DOptions(this, m_bUseCaCerts, m_fCaCertsFile);
	dOptions.setLocationRelativeTo(this);
	SwingHelper.showAndWait(dOptions);

	// Store/apply the chosen options:

	// CA certificates file
	File fTmp = dOptions.getCaCertsFile();

	if (!fTmp.equals(m_fCaCertsFile))
	{
		// CA certificates file changed - any stored CA certificates keystore is now invalid
		m_caCertsKeyStore = null;
	}

	m_fCaCertsFile = fTmp;

	// Use CA certificates?
	m_bUseCaCerts = dOptions.isUseCaCerts();

	// Look & feel
	String newLookFeelClassName = dOptions.getLookFeelClassName();

	// Look & feel decoration
	boolean bLookFeelDecoration = dOptions.isLookFeelDecoration();

	// Look & feel/decoration changed?
	// Note: UIManager.LookAndFeelInfo.getName() and LookAndFeel.getName() can be different for the same
	// L&F (one example is the GTK+ one in J2SE 5 RC2 (Linux), where the former is "GTK+" and the latter
	// is "GTK look and feel"). Therefore, compare the class names instead.
	if (newLookFeelClassName != null &&
	    (!newLookFeelClassName.equals(UIManager.getLookAndFeel().getClass().getName()) ||
	        bLookFeelDecoration != JFrame.isDefaultLookAndFeelDecorated()))
	{
		// Yes - save selections to be picked up by application preferences,
		lookFeelClassName = newLookFeelClassName;
		m_bLookFeelDecorationOptions = bLookFeelDecoration;
		saveAppPrefs();

		JFrame.setDefaultLookAndFeelDecorated(bLookFeelDecoration);
		JDialog.setDefaultLookAndFeelDecorated(bLookFeelDecoration);
		try
		{
			UIManager.setLookAndFeel(lookFeelClassName);
			SwingUtilities.updateComponentTreeUI(getRootPane());
			pack();
		}
		catch (Exception e)
		{
			DThrowable.showAndWait(this, null, e);
		}
	}
}
 
Example 15
Source File: FileChooserDemo.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    boolean selected = false;
    if (c instanceof JToggleButton) {
        selected = ((JToggleButton) c).isSelected();
    }

    if (c == openRadioButton) {
        chooser.setDialogType(OPEN_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == useEmbedInWizardCheckBox) {
        useControlsCheckBox.setEnabled(!selected);
        useControlsCheckBox.setSelected(!selected);
        chooser.setControlButtonsAreShown(!selected);
    } else if (c == useControlsCheckBox) {
        chooser.setControlButtonsAreShown(selected);
    } else if (c == enableDragCheckBox) {
        chooser.setDragEnabled(selected);
    } else if (c == saveRadioButton) {
        chooser.setDialogType(SAVE_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == customButton || c == customField) {
        customField.setEnabled(true);
        chooser.setDialogType(CUSTOM_DIALOG);
        repaint();
    } else if (c == showAllFilesFilterCheckBox) {
        chooser.setAcceptAllFileFilterUsed(selected);
    } else if (c == showImageFilesFilterCheckBox) {
        resetFileFilters(selected,
                showFullDescriptionCheckBox.isSelected());
        showFullDescriptionCheckBox.setEnabled(selected);
    } else if (c == setHiddenCheckBox) {
        chooser.setFileHidingEnabled(!selected);
    } else if (c == accessoryCheckBox) {
        if (selected) {
            chooser.setAccessory(previewer);
        } else {
            chooser.setAccessory(null);
        }
    } else if (c == useFileViewCheckBox) {
        if (selected) {
            chooser.setFileView(fileView);
        } else {
            chooser.setFileView(null);
        }
    } else if (c == useFileSystemViewCheckBox) {
        if (selected) {
            chooser.setFileSystemView(fileSystemView);
        } else {
            // Restore default behaviour
            chooser.setFileSystemView(FileSystemView.getFileSystemView());
        }
    } else if (c == showFullDescriptionCheckBox) {
        resetFileFilters(showImageFilesFilterCheckBox.isSelected(),
                selected);
    } else if (c == justFilesRadioButton) {
        chooser.setFileSelectionMode(FILES_ONLY);
    } else if (c == justDirectoriesRadioButton) {
        chooser.setFileSelectionMode(DIRECTORIES_ONLY);
    } else if (c == bothFilesAndDirectoriesRadioButton) {
        chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
    } else if (c == singleSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(false);
        }
    } else if (c == multiSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(true);
        }
    } else if (c == lafComboBox) {
        SupportedLaF supportedLaF = ((SupportedLaF) lafComboBox.
                getSelectedItem());
        LookAndFeel laf = supportedLaF.laf;
        try {
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(frame);
            if (chooser != null) {
                SwingUtilities.updateComponentTreeUI(chooser);
            }
            frame.pack();
        } catch (UnsupportedLookAndFeelException exc) {
            // This should not happen because we already checked
            ((DefaultComboBoxModel) lafComboBox.getModel()).
                    removeElement(supportedLaF);
        }
    }

}
 
Example 16
Source File: JConsole.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent event) {
	if (event.getPropertyName().equals("lookAndFeel")) {
		SwingUtilities.updateComponentTreeUI(menu);
	}
}
 
Example 17
Source File: FileChooserDemo.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    boolean selected = false;
    if (c instanceof JToggleButton) {
        selected = ((JToggleButton) c).isSelected();
    }

    if (c == openRadioButton) {
        chooser.setDialogType(OPEN_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == useEmbedInWizardCheckBox) {
        useControlsCheckBox.setEnabled(!selected);
        useControlsCheckBox.setSelected(!selected);
        chooser.setControlButtonsAreShown(!selected);
    } else if (c == useControlsCheckBox) {
        chooser.setControlButtonsAreShown(selected);
    } else if (c == enableDragCheckBox) {
        chooser.setDragEnabled(selected);
    } else if (c == saveRadioButton) {
        chooser.setDialogType(SAVE_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == customButton || c == customField) {
        customField.setEnabled(true);
        chooser.setDialogType(CUSTOM_DIALOG);
        repaint();
    } else if (c == showAllFilesFilterCheckBox) {
        chooser.setAcceptAllFileFilterUsed(selected);
    } else if (c == showImageFilesFilterCheckBox) {
        resetFileFilters(selected,
                showFullDescriptionCheckBox.isSelected());
        showFullDescriptionCheckBox.setEnabled(selected);
    } else if (c == setHiddenCheckBox) {
        chooser.setFileHidingEnabled(!selected);
    } else if (c == accessoryCheckBox) {
        if (selected) {
            chooser.setAccessory(previewer);
        } else {
            chooser.setAccessory(null);
        }
    } else if (c == useFileViewCheckBox) {
        if (selected) {
            chooser.setFileView(fileView);
        } else {
            chooser.setFileView(null);
        }
    } else if (c == useFileSystemViewCheckBox) {
        if (selected) {
            chooser.setFileSystemView(fileSystemView);
        } else {
            // Restore default behaviour
            chooser.setFileSystemView(FileSystemView.getFileSystemView());
        }
    } else if (c == showFullDescriptionCheckBox) {
        resetFileFilters(showImageFilesFilterCheckBox.isSelected(),
                selected);
    } else if (c == justFilesRadioButton) {
        chooser.setFileSelectionMode(FILES_ONLY);
    } else if (c == justDirectoriesRadioButton) {
        chooser.setFileSelectionMode(DIRECTORIES_ONLY);
    } else if (c == bothFilesAndDirectoriesRadioButton) {
        chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
    } else if (c == singleSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(false);
        }
    } else if (c == multiSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(true);
        }
    } else if (c == lafComboBox) {
        SupportedLaF supportedLaF = ((SupportedLaF) lafComboBox.
                getSelectedItem());
        LookAndFeel laf = supportedLaF.laf;
        try {
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(frame);
            if (chooser != null) {
                SwingUtilities.updateComponentTreeUI(chooser);
            }
            frame.pack();
        } catch (UnsupportedLookAndFeelException exc) {
            // This should not happen because we already checked
            ((DefaultComboBoxModel) lafComboBox.getModel()).
                    removeElement(supportedLaF);
        }
    }

}
 
Example 18
Source File: FileChooserDemo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    boolean selected = false;
    if (c instanceof JToggleButton) {
        selected = ((JToggleButton) c).isSelected();
    }

    if (c == openRadioButton) {
        chooser.setDialogType(OPEN_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == useEmbedInWizardCheckBox) {
        useControlsCheckBox.setEnabled(!selected);
        useControlsCheckBox.setSelected(!selected);
        chooser.setControlButtonsAreShown(!selected);
    } else if (c == useControlsCheckBox) {
        chooser.setControlButtonsAreShown(selected);
    } else if (c == enableDragCheckBox) {
        chooser.setDragEnabled(selected);
    } else if (c == saveRadioButton) {
        chooser.setDialogType(SAVE_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == customButton || c == customField) {
        customField.setEnabled(true);
        chooser.setDialogType(CUSTOM_DIALOG);
        repaint();
    } else if (c == showAllFilesFilterCheckBox) {
        chooser.setAcceptAllFileFilterUsed(selected);
    } else if (c == showImageFilesFilterCheckBox) {
        resetFileFilters(selected,
                showFullDescriptionCheckBox.isSelected());
        showFullDescriptionCheckBox.setEnabled(selected);
    } else if (c == setHiddenCheckBox) {
        chooser.setFileHidingEnabled(!selected);
    } else if (c == accessoryCheckBox) {
        if (selected) {
            chooser.setAccessory(previewer);
        } else {
            chooser.setAccessory(null);
        }
    } else if (c == useFileViewCheckBox) {
        if (selected) {
            chooser.setFileView(fileView);
        } else {
            chooser.setFileView(null);
        }
    } else if (c == useFileSystemViewCheckBox) {
        if (selected) {
            chooser.setFileSystemView(fileSystemView);
        } else {
            // Restore default behaviour
            chooser.setFileSystemView(FileSystemView.getFileSystemView());
        }
    } else if (c == showFullDescriptionCheckBox) {
        resetFileFilters(showImageFilesFilterCheckBox.isSelected(),
                selected);
    } else if (c == justFilesRadioButton) {
        chooser.setFileSelectionMode(FILES_ONLY);
    } else if (c == justDirectoriesRadioButton) {
        chooser.setFileSelectionMode(DIRECTORIES_ONLY);
    } else if (c == bothFilesAndDirectoriesRadioButton) {
        chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
    } else if (c == singleSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(false);
        }
    } else if (c == multiSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(true);
        }
    } else if (c == lafComboBox) {
        SupportedLaF supportedLaF = ((SupportedLaF) lafComboBox.
                getSelectedItem());
        LookAndFeel laf = supportedLaF.laf;
        try {
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(frame);
            if (chooser != null) {
                SwingUtilities.updateComponentTreeUI(chooser);
            }
            frame.pack();
        } catch (UnsupportedLookAndFeelException exc) {
            // This should not happen because we already checked
            ((DefaultComboBoxModel) lafComboBox.getModel()).
                    removeElement(supportedLaF);
        }
    }

}
 
Example 19
Source File: JSConsole.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    String plaf_name = null;
    if(cmd.equals("Load")) {
        String f = chooseFile();
        if(f != null) {
            f = f.replace('\\', '/');
            consoleTextArea.eval("load(\"" + f + "\");");
        }
    } else if(cmd.equals("Exit")) {
        System.exit(0);
    } else if(cmd.equals("Cut")) {
        consoleTextArea.cut();
    } else if(cmd.equals("Copy")) {
        consoleTextArea.copy();
    } else if(cmd.equals("Paste")) {
        consoleTextArea.paste();
    } else {
        if(cmd.equals("Metal")) {
            plaf_name = "javax.swing.plaf.metal.MetalLookAndFeel";
        } else if(cmd.equals("Windows")) {
            plaf_name = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
        } else if(cmd.equals("Motif")) {
            plaf_name = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        }
        if(plaf_name != null) {
            try {
                UIManager.setLookAndFeel(plaf_name);
                SwingUtilities.updateComponentTreeUI(this);
                consoleTextArea.postUpdateUI();
                // updateComponentTreeUI seems to mess up the file
                // chooser dialog, so just create a new one
                createFileChooser();
            } catch(Exception exc) {
                JOptionPane.showMessageDialog(this,
                                              exc.getMessage(),
                                              "Platform",
                                              JOptionPane.ERROR_MESSAGE);
            }
        }
    }

}
 
Example 20
Source File: FileChooserDemo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JComponent c = (JComponent) e.getSource();
    boolean selected = false;
    if (c instanceof JToggleButton) {
        selected = ((JToggleButton) c).isSelected();
    }

    if (c == openRadioButton) {
        chooser.setDialogType(OPEN_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == useEmbedInWizardCheckBox) {
        useControlsCheckBox.setEnabled(!selected);
        useControlsCheckBox.setSelected(!selected);
        chooser.setControlButtonsAreShown(!selected);
    } else if (c == useControlsCheckBox) {
        chooser.setControlButtonsAreShown(selected);
    } else if (c == enableDragCheckBox) {
        chooser.setDragEnabled(selected);
    } else if (c == saveRadioButton) {
        chooser.setDialogType(SAVE_DIALOG);
        customField.setEnabled(false);
        repaint();
    } else if (c == customButton || c == customField) {
        customField.setEnabled(true);
        chooser.setDialogType(CUSTOM_DIALOG);
        repaint();
    } else if (c == showAllFilesFilterCheckBox) {
        chooser.setAcceptAllFileFilterUsed(selected);
    } else if (c == showImageFilesFilterCheckBox) {
        resetFileFilters(selected,
                showFullDescriptionCheckBox.isSelected());
        showFullDescriptionCheckBox.setEnabled(selected);
    } else if (c == setHiddenCheckBox) {
        chooser.setFileHidingEnabled(!selected);
    } else if (c == accessoryCheckBox) {
        if (selected) {
            chooser.setAccessory(previewer);
        } else {
            chooser.setAccessory(null);
        }
    } else if (c == useFileViewCheckBox) {
        if (selected) {
            chooser.setFileView(fileView);
        } else {
            chooser.setFileView(null);
        }
    } else if (c == useFileSystemViewCheckBox) {
        if (selected) {
            chooser.setFileSystemView(fileSystemView);
        } else {
            // Restore default behaviour
            chooser.setFileSystemView(FileSystemView.getFileSystemView());
        }
    } else if (c == showFullDescriptionCheckBox) {
        resetFileFilters(showImageFilesFilterCheckBox.isSelected(),
                selected);
    } else if (c == justFilesRadioButton) {
        chooser.setFileSelectionMode(FILES_ONLY);
    } else if (c == justDirectoriesRadioButton) {
        chooser.setFileSelectionMode(DIRECTORIES_ONLY);
    } else if (c == bothFilesAndDirectoriesRadioButton) {
        chooser.setFileSelectionMode(FILES_AND_DIRECTORIES);
    } else if (c == singleSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(false);
        }
    } else if (c == multiSelectionRadioButton) {
        if (selected) {
            chooser.setMultiSelectionEnabled(true);
        }
    } else if (c == lafComboBox) {
        SupportedLaF supportedLaF = ((SupportedLaF) lafComboBox.
                getSelectedItem());
        LookAndFeel laf = supportedLaF.laf;
        try {
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(frame);
            if (chooser != null) {
                SwingUtilities.updateComponentTreeUI(chooser);
            }
            frame.pack();
        } catch (UnsupportedLookAndFeelException exc) {
            // This should not happen because we already checked
            ((DefaultComboBoxModel) lafComboBox.getModel()).
                    removeElement(supportedLaF);
        }
    }

}