Example usage for javax.swing ButtonGroup setSelected

List of usage examples for javax.swing ButtonGroup setSelected

Introduction

In this page you can find the example usage for javax.swing ButtonGroup setSelected.

Prototype

public void setSelected(ButtonModel m, boolean b) 

Source Link

Document

Sets the selected value for the ButtonModel.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JRadioButton radioButton = new JRadioButton();
    ButtonGroup group = new ButtonGroup();
    ButtonModel model = radioButton.getModel();
    group.setSelected(model, true);

}

From source file:FindingAButtonGroup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Group");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Examples");
    panel.setBorder(border);//  ww  w  .j  ava  2s  . c o  m
    ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JToggleButton("Toggle Button");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Radio Button");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JCheckBox("Check Box");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item");
    panel.add(abstract5);
    group.add(abstract5);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
    group.setSelected(abstract1.getModel(), true);
    Enumeration elements = group.getElements();
    while (elements.hasMoreElements()) {
        AbstractButton button = (AbstractButton) elements.nextElement();
        if (button.isSelected()) {
            System.out.println("The winner is: " + button.getText());
        }
    }
}

From source file:SettingSelectedAButtonGroup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Button Group");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Examples");
    panel.setBorder(border);// w  ww .  j a v  a2s  .  c o m
    ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JToggleButton("Toggle Button");
    panel.add(abstract1);
    group.add(abstract1);

    AbstractButton abstract2 = new JRadioButton("Radio Button");
    panel.add(abstract2);
    group.add(abstract2);

    AbstractButton abstract3 = new JCheckBox("Check Box");
    panel.add(abstract3);
    group.add(abstract3);

    AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item");
    panel.add(abstract4);
    group.add(abstract4);

    AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item");
    panel.add(abstract5);
    group.add(abstract5);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
    group.setSelected(abstract1.getModel(), true);

    Enumeration elements = group.getElements();
    while (elements.hasMoreElements()) {
        AbstractButton button = (AbstractButton) elements.nextElement();
        if (button.isSelected()) {
            System.out.println("The winner is: " + button.getText());
        }
    }
}

From source file:ASelectedButton.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Radio Buttons");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);/*www.  j a  v a 2 s  .c  o  m*/
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JToggleButton button = new JToggleButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Options");
    panel.setBorder(border);//from w w  w .  ja va  2s .c  om
    final ButtonGroup group = new ButtonGroup();
    AbstractButton abstract1 = new JRadioButton("One");
    panel.add(abstract1);
    group.add(abstract1);
    AbstractButton abstract2 = new JRadioButton("Two");
    panel.add(abstract2);
    group.add(abstract2);
    AbstractButton abstract3 = new JRadioButton("Three");
    panel.add(abstract3);
    group.add(abstract3);
    AbstractButton abstract4 = new JRadioButton("Four");
    panel.add(abstract4);
    group.add(abstract4);
    AbstractButton abstract5 = new JRadioButton("Five");
    panel.add(abstract5);
    group.add(abstract5);
    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Enumeration elements = group.getElements();
            while (elements.hasMoreElements()) {
                AbstractButton button = (AbstractButton) elements.nextElement();
                if (button.isSelected()) {
                    System.out.println("The winner is: " + button.getText());
                    break;
                }
            }
            group.setSelected(null, true);
        }
    };
    JButton button = new JButton("Show Selected");
    button.addActionListener(aListener);
    Container container = frame.getContentPane();
    container.add(panel, BorderLayout.CENTER);
    container.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private JMenu createViewMenu() {
    JMenu viewMenu = new JMenu("View");
    viewMenu.setMnemonic('v');

    JMenu lnfMenu = new JMenu("Look and Feel");
    lnfMenu.setMnemonic('f');

    ButtonGroup lnfGroup = new ButtonGroup();
    LookAndFeelInfo lnfs[] = UIManager.getInstalledLookAndFeels();
    String lnfCurrentName = null;
    LookAndFeel lnfCurrent = UIManager.getLookAndFeel();
    if (lnfCurrent != null) {
        lnfCurrentName = lnfCurrent.getClass().getName();
    }//from  w w  w  . j a v a 2 s  .  co m
    UISwitcher switcher = new UISwitcher();
    for (int i = 0; i < lnfs.length; i++) {
        JRadioButtonMenuItem lnfItem = new JRadioButtonMenuItem(lnfs[i].getName());
        lnfItem.addActionListener(switcher);
        lnfItem.setActionCommand(lnfs[i].getClassName());
        lnfGroup.add(lnfItem);
        lnfMenu.add(lnfItem);

        if (lnfs[i].getClassName().equals(lnfCurrentName)) {
            lnfGroup.setSelected(lnfItem.getModel(), true);
        }
    }
    viewMenu.add(lnfMenu);

    return viewMenu;
}

From source file:org.cds06.speleograph.graph.SeriesMenu.java

private JPopupMenu createPopupMenuForSeries(final Series series) {

    if (series == null)
        return new JPopupMenu();

    final JPopupMenu menu = new JPopupMenu(series.getName());

    menu.removeAll();//www.  j  a  v a  2  s . c o  m

    menu.add(new AbstractAction() {
        {
            putValue(NAME, "Renommer la srie");
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            menu.setVisible(false);
            String newName = "";
            while (newName == null || newName.equals("")) {
                newName = (String) JOptionPane.showInputDialog(application,
                        "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null,
                        series.getName());
            }
            series.setName(newName);
        }
    });

    if (series.hasOwnAxis()) {
        menu.add(new AbstractAction() {

            {
                putValue(NAME, "Supprimer l'axe spcifique");
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?",
                        "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                    series.setAxis(null);
                }
            }
        });
    } else {
        menu.add(new JMenuItem(new AbstractAction() {

            {
                putValue(NAME, "Crer un axe spcifique pour la srie");
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?",
                        series.getAxis().getLabel());
                if (name == null || "".equals(name))
                    return; // User has canceled
                series.setAxis(new NumberAxis(name));
            }
        }));
    }

    menu.add(new SetTypeMenu(series));

    if (series.isWater()) {
        menu.addSeparator();
        menu.add(new SumOnPeriodAction(series));
        menu.add(new CreateCumulAction(series));
    }
    if (series.isWaterCumul()) {
        menu.addSeparator();
        menu.add(new SamplingAction(series));
    }

    if (series.isPressure()) {
        menu.addSeparator();
        menu.add(new CorrelateAction(series));
        menu.add(new WaterHeightAction(series));
    }

    menu.addSeparator();

    menu.add(new AbstractAction() {
        {
            String name;
            if (series.canUndo())
                name = "Annuler " + series.getItemsName();
            else
                name = series.getLastUndoName();

            putValue(NAME, name);

            if (series.canUndo())
                setEnabled(true);
            else {
                setEnabled(false);
            }

        }

        @Override
        public void actionPerformed(ActionEvent e) {
            series.undo();
        }
    });

    menu.add(new AbstractAction() {
        {
            String name;
            if (series.canRedo()) {
                name = "Refaire " + series.getNextRedoName();
                setEnabled(true);
            } else {
                name = series.getNextRedoName();
                setEnabled(false);
            }

            putValue(NAME, name);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            series.redo();
        }
    });

    menu.add(new AbstractAction() {
        {
            putValue(NAME, I18nSupport.translate("menus.serie.resetSerie"));
            if (series.canUndo())
                setEnabled(true);
            else
                setEnabled(false);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            series.reset();
        }
    });

    menu.add(new LimitDateRangeAction(series));

    menu.add(new HourSettingAction(series));

    menu.addSeparator();

    {
        JMenuItem deleteItem = new JMenuItem("Supprimer la srie");
        deleteItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (JOptionPane.showConfirmDialog(application,
                        "tes-vous sur de vouloir supprimer cette srie ?\n"
                                + "Cette action est dfinitive.",
                        "Confirmation", JOptionPane.OK_CANCEL_OPTION,
                        JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
                    series.delete();
                }
            }
        });
        menu.add(deleteItem);
    }

    menu.addSeparator();

    {
        final JMenuItem up = new JMenuItem("Remonter dans la liste"),
                down = new JMenuItem("Descendre dans la liste");
        ActionListener listener = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getSource().equals(up)) {
                    series.upSeriesInList();
                } else {
                    series.downSeriesInList();
                }
            }
        };
        up.addActionListener(listener);
        down.addActionListener(listener);
        if (series.isFirst()) {
            menu.add(down);
        } else if (series.isLast()) {
            menu.add(up);
        } else {
            menu.add(up);
            menu.add(down);
        }
    }

    menu.addSeparator();

    {
        menu.add(new SeriesInfoAction(series));
    }

    {
        JMenuItem colorItem = new JMenuItem("Couleur de la srie");
        colorItem.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                series.setColor(JColorChooser.showDialog(application,
                        I18nSupport.translate("actions.selectColorForSeries"), series.getColor()));
            }
        });
        menu.add(colorItem);
    }

    {
        JMenu plotRenderer = new JMenu("Affichage de la srie");
        final ButtonGroup modes = new ButtonGroup();
        java.util.List<DrawStyle> availableStyles;
        if (series.isMinMax()) {
            availableStyles = DrawStyles.getDrawableStylesForHighLow();
        } else {
            availableStyles = DrawStyles.getDrawableStyles();
        }
        for (final DrawStyle s : availableStyles) {
            final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s));
            item.addChangeListener(new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                    if (item.isSelected())
                        series.setStyle(s);
                }
            });
            modes.add(item);
            if (s.equals(series.getStyle())) {
                modes.setSelected(item.getModel(), true);
            }
            plotRenderer.add(item);
        }
        menu.add(plotRenderer);
    }
    menu.addSeparator();

    menu.add(new AbstractAction() {
        {
            putValue(Action.NAME, "Fermer le fichier");
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(application,
                    "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
                final File f = series.getOrigin();
                for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) {
                    if (s.getOrigin().equals(f))
                        s.delete();
                }
            }
        }
    });

    return menu;
}

From source file:ome.formats.importer.gui.ImportDialog.java

/**
 * Display a dialog so the user can choose project/dataset for importing
 * //from  w  w w  .  ja v a  2 s  .  c  om
 * @param config - ImportConfig
 * @param owner - parent frame
 * @param title - dialog title
 * @param modal - modal yes/no
 * @param store - Initialized OMEROMetadataStore
 */
ImportDialog(ImportConfig config, JFrame owner, String title, boolean modal, OMEROMetadataStoreClient store) {
    this.store = store;

    if (store != null) {
        projectItems = ProjectItem.createProjectItems(store.getProjects());
    }

    setLocation(200, 200);
    setTitle(title);
    setModal(modal);
    setResizable(false);
    setSize(new Dimension(dialogWidth, dialogHeight));
    setLocationRelativeTo(owner);

    tabbedPane = new JTabbedPane();
    tabbedPane.setOpaque(false); // content panes must be opaque

    this.config = config;

    /////////////////////// START IMPORT PANEL ////////////////////////

    // Set up the import panel for tPane, quit, and send buttons

    double mainTable[][] = { { TableLayout.FILL, 120, 5, 160, TableLayout.FILL }, // columns
            { TableLayout.PREFERRED, 10, TableLayout.PREFERRED, TableLayout.FILL, 40, 30 } }; // rows

    importPanel = GuiCommonElements.addMainPanel(tabbedPane, mainTable, 0, 10, 0, 10, debug);

    String message = "Import these images into which dataset?";
    GuiCommonElements.addTextPane(importPanel, message, "0, 0, 4, 0", debug);

    // Set up the project/dataset table
    double pdTable[][] = { { TableLayout.FILL, 5, 40 }, // columns
            { 35, 35 } }; // rows

    // Panel containing the project / dataset layout

    pdPanel = GuiCommonElements.addMainPanel(importPanel, pdTable, 0, 0, 0, 0, debug);

    pbox = GuiCommonElements.addComboBox(pdPanel, "Project: ", projectItems, 'P',
            "Select dataset to use for this import.", 60, "0,0,F,C", debug);
    pbox.addActionListener(this);

    // Fixing broken mac buttons.
    String offsetButtons = ",C";
    //if (GuiCommonElements.offsetButtons == true) offsetButtons = ",t";

    addProjectBtn = GuiCommonElements.addIconButton(pdPanel, "", addIcon, 20, 60, null, null,
            "2,0,f" + offsetButtons, debug);
    addProjectBtn.addActionListener(this);

    dbox = GuiCommonElements.addComboBox(pdPanel, "Dataset: ", datasetItems, 'D',
            "Select dataset to use for this import.", 60, "0,1,F,C", debug);

    dbox.setEnabled(false);

    addDatasetBtn = GuiCommonElements.addIconButton(pdPanel, "", addIcon, 20, 60, null, null,
            "2,1,f" + offsetButtons, debug);
    addDatasetBtn.addActionListener(this);

    //addDatasetBtn.setEnabled(false);

    importPanel.add(pdPanel, "0, 2, 4, 2");

    // File naming section

    double namedTable[][] = { { 30, TableLayout.FILL }, // columns
            { 24, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows      

    namedPanel = GuiCommonElements.addBorderedPanel(importPanel, namedTable, "File Naming", debug);

    String fullPathTooltip = "The full file+path name for the file. For example: \"c:/myfolder/mysubfolder/myfile.dv\"";

    String partPathTooltip = "A partial path and file name for the file. For example: \"mysubfolder/myfile.dv\"";

    fullPathButton = GuiCommonElements.addRadioButton(namedPanel, "the full path+file name of your file", 'u',
            fullPathTooltip, "1,1", debug);
    fullPathButton.addActionListener(this);

    partPathButton = GuiCommonElements.addRadioButton(namedPanel, "a partial path+file name with...", 'u',
            partPathTooltip, "1,2", debug);
    partPathButton.addActionListener(this);

    numOfDirectoriesField = GuiCommonElements.addWholeNumberField(namedPanel, "", "0",
            "of the directories immediately before it.", 0, "Add this number of directories to the file names",
            3, 40, "1,3,L,C", debug);
    numOfDirectoriesField.addActionListener(this);

    numOfDirectoriesField.setText(Integer.toString(config.getNumOfDirectories()));

    // focus on the partial path button if you enter the numofdirfield
    numOfDirectoriesField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            partPathButton.setSelected(true);
        }

        public void focusLost(FocusEvent e) {
        }

    });

    ButtonGroup group = new ButtonGroup();
    group.add(fullPathButton);
    group.add(partPathButton);

    //if (config.useFullPath.get() == true )
    if (config.getUserFullPath() == true)
        group.setSelected(fullPathButton.getModel(), true);
    else
        group.setSelected(partPathButton.getModel(), true);

    useCustomNamingChkBox = GuiCommonElements.addCheckBox(namedPanel,
            "Override default file naming. Instead use:", "0,0,1,0", debug);
    useCustomNamingChkBox.addActionListener(this);
    //if (config.useCustomImageNaming.get() == true)
    if (config.getCustomImageNaming() == true) {
        useCustomNamingChkBox.setSelected(true);
        enabledPathButtons(true);
    } else {
        useCustomNamingChkBox.setSelected(false);
        enabledPathButtons(false);
    }

    importPanel.add(namedPanel, "0, 3, 4, 2");

    archiveImage = GuiCommonElements.addCheckBox(importPanel,
            "Archive the original imported file(s) to the server.", "0,4,4,4", debug);
    archiveImage.addActionListener(this);

    archiveImage.setSelected(config.archiveImage.get());

    // Override config.archiveImage.get() if 
    // import.config is set for forceFileArchiveOn
    if (config.getForceFileArchiveOn() == true)
        archiveImage.setSelected(true);

    if (ARCHIVE_ENABLED) {
        archiveImage.setVisible(true);
    } else {
        archiveImage.setVisible(false);
    }

    // Buttons at the bottom of the form

    cancelBtn = GuiCommonElements.addButton(importPanel, "Cancel", 'L', "Cancel", "1, 5, f, c", debug);
    cancelBtn.addActionListener(this);

    importBtn = GuiCommonElements.addButton(importPanel, "Add to Queue", 'Q', "Import", "3, 5, f, c", debug);
    importBtn.addActionListener(this);
    importBtn.setEnabled(false);
    this.getRootPane().setDefaultButton(importBtn);

    this.getRootPane().setDefaultButton(importBtn);
    GuiCommonElements.enterPressesWhenFocused(importBtn);

    /////////////////////// START METADATA PANEL ////////////////////////

    double metadataTable[][] = { { TableLayout.FILL }, // columns
            { TableLayout.FILL, 10, TableLayout.FILL } }; // rows

    metadataPanel = GuiCommonElements.addMainPanel(tabbedPane, metadataTable, 0, 10, 0, 10, debug);

    double pixelTable[][] = { { 10, TableLayout.FILL, 10, TableLayout.FILL, 10, TableLayout.FILL, 10 }, // columns
            { 68, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows      

    pixelPanel = GuiCommonElements.addBorderedPanel(metadataPanel, pixelTable, "Pixel Size Defaults", debug);

    message = "These X, Y & Z pixel size values (typically measured in microns) "
            + "will be used if no values are included in the image file metadata:";
    GuiCommonElements.addTextPane(pixelPanel, message, "1, 0, 6, 0", debug);

    xPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "X: ", null, "", 0, "", 8, 80, "1,1,L,C",
            debug);

    yPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "Y: ", null, "", 0, "", 8, 80, "3,1,L,C",
            debug);

    zPixelSize = GuiCommonElements.addDecimalNumberField(pixelPanel, "Z: ", null, "", 0, "", 8, 80, "5,1,L,C",
            debug);

    metadataPanel.add(pixelPanel, "0, 0");

    double channelTable[][] = { { 10, TableLayout.FILL, 10, TableLayout.FILL, 10, TableLayout.FILL, 10 }, // columns
            { 68, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL } }; // rows      

    channelPanel = GuiCommonElements.addBorderedPanel(metadataPanel, channelTable, "Channel Defaults", debug);

    rChannel = GuiCommonElements.addWholeNumberField(channelPanel, "R: ", "0", "", 0, "", 8, 80, "1,1,L,C",
            debug);

    gChannel = GuiCommonElements.addWholeNumberField(channelPanel, "G: ", "1", "", 0, "", 8, 80, "3,1,L,C",
            debug);

    bChannel = GuiCommonElements.addWholeNumberField(channelPanel, "B: ", "2", "", 0, "", 8, 80, "5,1,L,C",
            debug);

    message = "These RGB channel wavelengths (typically measured in nanometers)"
            + " will be used if no channel values are included in the image file metadata:";
    GuiCommonElements.addTextPane(channelPanel, message, "1, 0, 6, 0", debug);

    //metadataPanel.add(channelPanel, "0, 2");

    /////////////////////// START TABBED PANE ////////////////////////

    this.add(tabbedPane);
    tabbedPane.addTab("Import Settings", null, importPanel, "Import Settings");
    tabbedPane.addTab("Metadata Defaults", null, metadataPanel, "Metadata Defaults");

    getProjectDatasets(projectItems[0].getProject());
    buildProjectsAndDatasets();
    setVisible(true);
}

From source file:org.languagetool.gui.Main.java

private void addLookAndFeelMenuItem(JMenu lafMenu, UIManager.LookAndFeelInfo laf, ButtonGroup buttonGroup) {
    JRadioButtonMenuItem lfItem = new JRadioButtonMenuItem(new SelectLFAction(laf));
    lafMenu.add(lfItem);/*www  . jav  a2  s.  c  om*/
    buttonGroup.add(lfItem);
    if (laf.getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) {
        buttonGroup.setSelected(lfItem.getModel(), true);
    }
}

From source file:renderer.DependencyGrapher.java

/**
 * create an instance of a simple graph in two views with controls to
 * demo the features.//from  w  w  w.j  av  a 2  s  .  c o m
 * 
 */
public DependencyGrapher() {

    // create a simple graph for the demo
    final DependencyDirectedSparceMultiGraph<String, Number> graph = createGraph(); //TestGraphs.getOneComponentGraph();

    // the preferred sizes for the two views

    // create one layout for the graph
    final FRLayout2<String, Number> layout = new FRLayout2<String, Number>(graph);
    layout.setMaxIterations(500);

    VisualizationModel<String, Number> vm = new DefaultVisualizationModel<String, Number>(layout,
            preferredSize1);

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            if (graph.getEdgeAttributes(e) != null) {
                return graph.getEdgeAttributes(e).toString();
            }
            return null;
        }
    };
    // create 2 views that share the same model
    final VisualizationViewer<String, Number> vv = new VisualizationViewer<String, Number>(vm, preferredSize1);
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeLabelTransformer(stringer);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String, Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.red, Color.yellow));
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    // add default listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());

    //      ToolTipManager.sharedInstance().setDismissDelay(10000);

    Container content = getContentPane();
    Container panel = new JPanel(new BorderLayout());

    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    panel.add(gzsp);

    helpDialog = new JDialog();
    helpDialog.getContentPane().add(new JLabel(instructions));

    RenderContext<String, Number> rc = vv.getRenderContext();
    AnnotatingGraphMousePlugin annotatingPlugin = new AnnotatingGraphMousePlugin(rc);
    // create a GraphMouse for the main view
    // 
    final AnnotatingModalGraphMouse graphMouse = new AnnotatingModalGraphMouse(rc, annotatingPlugin);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton filterReset = new JButton("Reset");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JButton filterFilter = new JButton("Filter");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JRadioButton filterDirectionInOut = new JRadioButton("In/Out");
    filterDirectionInOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN_OUT);
            _filterEdgeDirection = EdgeType.IN_OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionIn = new JRadioButton("In");
    filterDirectionIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN);
            _filterEdgeDirection = EdgeType.IN;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionOut = new JRadioButton("Out");
    filterDirectionOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.OUT);
            _filterEdgeDirection = EdgeType.OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    ButtonGroup filterRadios = new ButtonGroup();
    filterRadios.add(filterDirectionInOut);
    filterRadios.add(filterDirectionIn);
    filterRadios.add(filterDirectionOut);
    filterRadios.setSelected(filterDirectionInOut.getModel(), true);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.setSelectedItem(ModalGraphMouse.Mode.PICKING);

    final JComboBox filterBox = new JComboBox(graph.getVertices().toArray());
    filterBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            _filterChoice = filterBox.getSelectedItem().toString();
            System.out.println(_filterChoice);
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            helpDialog.pack();
            helpDialog.setVisible(true);
        }
    });

    JPanel controls = new JPanel();

    JPanel modeControls = new JPanel();
    modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modeControls.add(graphMouse.getModeComboBox());
    controls.add(modeControls);

    JPanel annotationControlPanel = new JPanel();
    annotationControlPanel.setBorder(BorderFactory.createTitledBorder("Annotation Controls"));

    AnnotationControls annotationControls = new AnnotationControls(annotatingPlugin);

    annotationControlPanel.add(annotationControls.getAnnotationsToolBar());
    controls.add(annotationControlPanel);

    JPanel helpControls = new JPanel();
    helpControls.setBorder(BorderFactory.createTitledBorder("Help"));
    helpControls.add(help);
    controls.add(helpControls);

    JPanel filterControls = new JPanel();
    filterControls.setBorder(BorderFactory.createTitledBorder("Filter"));
    filterControls.add(filterBox);
    filterControls.add(filterDirectionInOut);
    filterControls.add(filterDirectionIn);
    filterControls.add(filterDirectionOut);
    filterControls.add(filterReset);
    controls.add(filterControls);

    content.add(panel);
    content.add(controls, BorderLayout.SOUTH);

}