Example usage for javax.swing BoxLayout X_AXIS

List of usage examples for javax.swing BoxLayout X_AXIS

Introduction

In this page you can find the example usage for javax.swing BoxLayout X_AXIS.

Prototype

int X_AXIS

To view the source code for javax.swing BoxLayout X_AXIS.

Click Source Link

Document

Specifies that components should be laid out left to right.

Usage

From source file:LocationSensitiveDemo.java

public LocationSensitiveDemo() {
    super("Location Sensitive Drag and Drop Demo");

    treeModel = getDefaultTreeModel();/*from   ww w. ja va 2 s  .  com*/
    tree = new JTree(treeModel);
    tree.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setDropMode(DropMode.ON);
    namesPath = tree.getPathForRow(2);
    tree.expandRow(2);
    tree.expandRow(1);
    tree.setRowHeight(0);

    tree.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!info.isDrop()) {
                return false;
            }

            String item = (String) indicateCombo.getSelectedItem();

            if (item.equals("Always")) {
                info.setShowDropLocation(true);
            } else if (item.equals("Never")) {
                info.setShowDropLocation(false);
            }

            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            TreePath path = dl.getPath();

            // we don't support invalid paths or descendants of the names folder
            if (path == null || namesPath.isDescendant(path)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            // if we can't handle the import, say so
            if (!canImport(info)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            // fetch the path and child index from the drop location
            TreePath path = dl.getPath();
            int childIndex = dl.getChildIndex();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            // if child index is -1, the drop was on top of the path, so we'll
            // treat it as inserting at the end of that path's list of children
            if (childIndex == -1) {
                childIndex = tree.getModel().getChildCount(path.getLastPathComponent());
            }

            // create a new node to represent the data and insert it into the model
            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(data);
            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            treeModel.insertNodeInto(newNode, parentNode, childIndex);

            // make the new node visible and scroll so that it's visible
            tree.makeVisible(path.pathByAddingChild(newNode));
            tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode)));

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt("String " + (++count), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue("String 0123456789");
    model.insertElementAt("String " + count, 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    indicateCombo = new JComboBox(new String[] { "Default", "Always", "Never" });
    indicateCombo.setSelectedItem("INSERT");

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    wrap = new JPanel();
    wrap.add(new JLabel("Show drop location:"));
    wrap.add(indicateCombo);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.SOUTH);

    getContentPane().setPreferredSize(new Dimension(400, 450));
}

From source file:medsavant.uhn.cancer.UserCommentApp.java

private JPanel getStatusIconPanel(final UserCommentGroup lcg, final UserComment lc) {
    JPanel sip = new JPanel();
    sip.setLayout(new BoxLayout(sip, BoxLayout.X_AXIS));

    JPanel statusIconPanel = new StatusIconPanel(ICON_WIDTH, ICON_HEIGHT, false, lc.isApproved(),
            lc.isIncluded(), lc.isDeleted());

    sip.add(statusIconPanel);/*from www  .j  ava2  s.  com*/
    sip.add(Box.createHorizontalGlue());

    //technicains and admins can change status, but technicians can't.
    if (roleManager.checkRole(GENETIC_COUNSELLOR_ROLENAME) || roleManager.checkRole(RESIDENT_ROLENAME)) {
        JButton statusEditButton = new JButton(new ImageIcon(EDIT_STATUS_BUTTON_ICON.getImage()
                .getScaledInstance(ICON_WIDTH, ICON_HEIGHT, java.awt.Image.SCALE_SMOOTH)));

        statusEditButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                editStatus(lcg, lc);
            }
        });
        sip.add(statusEditButton);
    }

    return sip;
}

From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java

protected JPanel buildMeasureCountSubPanel() {
    JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.add(measureCountLabel = new MeasureCountLabel());
    panel.setAlignmentX(Component.LEFT_ALIGNMENT);

    return (panel);
}

From source file:diet.gridr.g5k.gui.ClusterInfoPanel.java

/**
 * Method returning the selectionChartPanel
 *
 * @return the selection chart panel/*from ww  w  .j a v  a  2 s  .c o  m*/
 */
private JPanel getSelectionChartPanel() {
    if (selectionChartPanel == null) {
        selectionChartPanel = new JPanel();
        selectionChartPanel.setLayout(new BoxLayout(selectionChartPanel, BoxLayout.X_AXIS));
        JLabel selectionChartLabel = new JLabel("Available charts: ");
        selectionChartPanel.add(selectionChartLabel);
        selectionChartPanel.add(Box.createHorizontalStrut(10));
        selectionChartPanel.add(getSelectionComboBox());
        selectionChartPanel.add(Box.createHorizontalGlue());

        if (Config.getBatchScheduler(G5kSite.getIndexForSite(siteName)).equalsIgnoreCase("OAR1")) {
            JButton button = new JButton("Jobs Gantt Chart");
            selectionChartPanel.add(button);
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Iterator<String> iter = jobsMap.keySet().iterator();
                    ArrayList<GridJob> jobsList = new ArrayList<GridJob>();
                    while (iter.hasNext()) {
                        jobsList.add(jobsMap.get(iter.next()));
                    }
                    new GanttChart("Jobs Gantt Chart", siteName, jobsList, connection);
                }
            });
        }
    }
    return selectionChartPanel;
}

From source file:diet.gridr.g5k.gui.G5kSummaryChart.java

/**
 * Method returning the chart selection panel
 *
 * @return panel for the selection of a chart to display
 *///from  w w w .  j  a v  a  2  s  .c o m
private JPanel getChartSelectionPanel() {
    if (chartSelectionPanel == null) {
        chartSelectionPanel = new JPanel();
        chartSelectionPanel.setLayout(new BoxLayout(chartSelectionPanel, BoxLayout.X_AXIS));
        chartSelectionLabel = new JLabel("Available charts :");
        chartSelectionPanel.add(chartSelectionLabel);
        chartSelectionPanel.add(Box.createHorizontalStrut(10));
        chartSelectionPanel.add(getChartSelectionComboBox());
        chartSelectionPanel.add(Box.createHorizontalGlue());
    }
    return chartSelectionPanel;
}

From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java

protected JPanel buildResultsSubPanel() {
    final JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.add(new JLabel(resourceBundle.getString("Weight") + ":"));
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(weightTxt);//  w ww . jav  a  2  s  . c  o m
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(new JLabel(resourceBundle.getString("kg")));
    panel.setAlignmentX(Component.LEFT_ALIGNMENT);

    return panel;
}

From source file:e3fraud.gui.MainWindow.java

public MainWindow() {
    super(new BorderLayout(5, 5));

    extended = false;//www . jav  a2s . c  om

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(10, 50);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    logScrollPane = new JScrollPane(log);
    DefaultCaret caret = (DefaultCaret) log.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    //        create the progress bar
    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(progressBar.getMinimum());
    progressBar.setVisible(false);
    progressBar.setStringPainted(true);
    //Create the settings pane
    generationSettingLabel = new JLabel("Generate:");
    SpinnerModel collusionsSpinnerModel = new SpinnerNumberModel(1, 0, 3, 1);
    collusionSettingsPanel = new JPanel(new FlowLayout()) {
        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    // collusionSettingsPanel.setLayout(new BoxLayout(collusionSettingsPanel, BoxLayout.X_AXIS));
    collusionsButton = new JSpinner(collusionsSpinnerModel);
    collusionsLabel = new JLabel("collusion(s)");
    collusionSettingsPanel.add(collusionsButton);
    collusionSettingsPanel.add(collusionsLabel);

    rankingSettingLabel = new JLabel("Rank by:");
    lossButton = new JRadioButton("loss");
    lossButton.setToolTipText("Sort sub-ideal models based on loss for Target of Assessment (high -> low)");
    gainButton = new JRadioButton("gain");
    gainButton.setToolTipText(
            "Sort sub-ideal models based on gain of any actor except Target of Assessment (high -> low)");
    lossGainButton = new JRadioButton("loss + gain");
    lossGainButton.setToolTipText(
            "Sort sub-ideal models based on loss for Target of Assessment and, if equal, on gain of any actor except Target of Assessment");
    //gainLossButton = new JRadioButton("gain + loss");
    lossGainButton.setSelected(true);
    rankingGroup = new ButtonGroup();
    rankingGroup.add(lossButton);
    rankingGroup.add(gainButton);
    rankingGroup.add(lossGainButton);
    //rankingGroup.add(gainLossButton);
    groupingSettingLabel = new JLabel("Group by:");
    groupingButton = new JCheckBox("collusion");
    groupingButton.setToolTipText(
            "Groups sub-ideal models based on the pair of actors colluding before ranking them");
    groupingButton.setSelected(false);
    refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(this);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS));
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(generationSettingLabel);
    collusionSettingsPanel.setAlignmentX(LEFT_ALIGNMENT);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(collusionSettingsPanel);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    rankingSettingLabel.setAlignmentY(TOP_ALIGNMENT);
    settingsPanel.add(rankingSettingLabel);
    settingsPanel.add(lossButton);
    settingsPanel.add(gainButton);
    settingsPanel.add(lossGainButton);
    //settingsPanel.add(gainLossButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(groupingSettingLabel);
    settingsPanel.add(groupingButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPanel.add(refreshButton);
    settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
    progressBar.setPreferredSize(
            new Dimension(settingsPanel.getSize().width, progressBar.getPreferredSize().height));
    settingsPanel.add(progressBar);

    //Create the result tree
    root = new DefaultMutableTreeNode("No models to display");
    treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel);
    //tree.setUI(new CustomTreeUI());
    tree.setCellRenderer(new CustomTreeCellRenderer(tree));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setLargeModel(true);
    resultScrollPane = new JScrollPane(tree);
    tree.addTreeSelectionListener(treeSelectionListener);

    //tree.setShowsRootHandles(true);
    //Create a file chooser for saving
    sfc = new JFileChooser();
    FileFilter jpegFilter = new FileNameExtensionFilter("JPEG image", new String[] { "jpg", "jpeg" });
    sfc.addChoosableFileFilter(jpegFilter);
    sfc.setFileFilter(jpegFilter);

    //Create a file chooser for loading
    fc = new JFileChooser();
    FileFilter rdfFilter = new FileNameExtensionFilter("RDF file", "RDF");
    fc.addChoosableFileFilter(rdfFilter);
    fc.setFileFilter(rdfFilter);

    //Create the open button.  
    openButton = new JButton("Load model", createImageIcon("images/Open24.png"));
    openButton.addActionListener(this);
    openButton.setToolTipText("Load a e3value model");

    //Create the ideal graph button. 
    idealGraphButton = new JButton("Show ideal graph", createImageIcon("images/Plot.png"));
    idealGraphButton.setToolTipText("Display ideal profitability graph");
    idealGraphButton.addActionListener(this);

    Dimension thinButtonDimension = new Dimension(15, 420);

    //Create the expand subideal graph button. 
    expandButton = new JButton(">");
    expandButton.setPreferredSize(thinButtonDimension);
    expandButton.setMargin(new Insets(0, 0, 0, 0));
    expandButton.setToolTipText("Expand to show non-ideal profitability graph for selected model");
    expandButton.addActionListener(this);

    //Create the collapse sub-ideal graph button. 
    collapseButton = new JButton("<");
    collapseButton.setPreferredSize(thinButtonDimension);
    collapseButton.setMargin(new Insets(0, 0, 0, 0));
    collapseButton.setToolTipText("Collapse non-ideal profitability graph for selected model");
    collapseButton.addActionListener(this);

    //Create the generation button. 
    generateButton = new JButton("Generate sub-ideal models", createImageIcon("images/generate.png"));
    generateButton.addActionListener(this);
    generateButton.setToolTipText("Generate sub-ideal models for the e3value model currently loaded");

    //Create the chart panel
    chartPane = new JPanel();
    chartPane.setLayout(new FlowLayout(FlowLayout.LEFT));
    chartPane.add(expandButton);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(openButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(20, 0)));
    buttonPanel.add(generateButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(idealGraphButton);

    //Add the buttons, the ranking options, the result list and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(settingsPanel, BorderLayout.LINE_START);
    add(resultScrollPane, BorderLayout.CENTER);

    add(logScrollPane, BorderLayout.PAGE_END);
    add(chartPane, BorderLayout.LINE_END);
    //and make a nice border around it
    setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
}

From source file:edu.virginia.speclab.juxta.author.view.export.WebServiceExportDialog.java

private Component createButtonBar() {
    JPanel p = new JPanel();
    p.setBackground(Color.white);
    p.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

    this.exportBtn = new JButton("Export");
    this.exportBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (exportBtn.getText().equals("View")) {
                viewWebServiceData();//from  w  ww  .  ja v a  2 s .com
            } else {
                onExportClicked();
            }
        }
    });

    this.closeBtn = new JButton("Cancel");
    getRootPane().setDefaultButton(this.exportBtn);
    this.closeBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancelClicked();
        }
    });

    p.add(Box.createHorizontalGlue());
    p.add(this.closeBtn);
    p.add(this.exportBtn);

    return p;
}

From source file:medsavant.uhn.cancer.AddNewCommentDialog.java

private JPanel getMainPanel() {
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    if (selectedOntologyTerm == null) {
        mainPanel.add(getHeader(//from ww w . j  a  v  a 2 s.  c  o m
                UserCommentApp.getDefaultOntologyType().name() + " terms associated with this variant"));
        JButton selectNoneButton = new JButton("Clear Selections");
        selectNoneButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                clearSelections();
            }
        });
        mainPanel.add(selectNoneButton);
        mainPanel.add(getOntologyTermsForThisVariant());
        mainPanel.add(getHeader("Comment"));
    } else {
        mainPanel.add(getHeader("Comment for " + UserCommentApp.getDefaultOntologyType().name() + " term "
                + selectedOntologyTerm.getName()));
    }

    commentBox = new JTextArea("", DEFAULT_COMMENTBOX_WIDTH, DEFAULT_COMMENTBOX_HEIGHT);
    commentBox.setLineWrap(true);
    JPanel textBoxPanel = new JPanel();
    textBoxPanel.setLayout(new BoxLayout(textBoxPanel, BoxLayout.X_AXIS));
    textBoxPanel.add(Box.createHorizontalGlue());
    textBoxPanel.add(new JScrollPane(commentBox));
    textBoxPanel.add(Box.createHorizontalGlue());

    mainPanel.add(textBoxPanel);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    JButton OKButton = new JButton("OK");
    OKButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                String sessID = LoginController.getSessionID();
                int projId = ProjectController.getInstance().getCurrentProjectID();
                int refId = ReferenceController.getInstance().getCurrentReferenceID();
                UserCommentGroup lcg = MedSavantClient.VariantManager.getUserCommentGroup(sessID, projId, refId,
                        variantRecord);
                if (lcg == null) {
                    lcg = MedSavantClient.VariantManager.createUserCommentGroup(sessID, projId, refId,
                            variantRecord);
                }
                submitComment(lcg);
                dispose();
            } catch (Exception ex) {
                ex.printStackTrace();
                LOG.error("Error: ", ex);
                DialogUtils.displayException("Error", ex.getLocalizedMessage(), ex);
            }
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    buttonPanel.add(OKButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(Box.createHorizontalGlue());
    mainPanel.add(buttonPanel);
    return mainPanel;
}

From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java

/**
 * Build action buttons sub panel/* ww  w  .  j av  a2 s. c o m*/
 */
protected JPanel buildActionButtonSubPanel() {
    JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

    panel.add(Box.createHorizontalGlue());
    panel.add(saveButton);

    JButton resetButton = new JButton(resourceBundle.getString("Reset"));
    resetButton.setMnemonic('R');
    resetButton.setToolTipText(resourceBundle.getString("ToolTip.Reset_measurement"));
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(resetButton);

    JButton cancelButton = new JButton(resourceBundle.getString("Cancel"));
    cancelButton.setMnemonic('A');
    cancelButton.setToolTipText(resourceBundle.getString("ToolTip.Cancel_measurement"));
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(cancelButton);

    JButton configureButton = new JButton(resourceBundle.getString("Configure"));
    configureButton.setMnemonic('C');
    configureButton.setToolTipText(resourceBundle.getString("ToolTip.Configure"));
    panel.add(Box.createRigidArea(new Dimension(10, 0)));
    panel.add(configureButton);

    // Configure button listener
    configureButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            configure();
        }
    });

    // Reset button listener
    resetButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            clearData();
        }
    });

    // Save button listener.
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            sendOutputToServer();
        }
    });

    // Cancel button listener.
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            confirmOnExit();
        }
    });

    panel.setAlignmentX(Component.LEFT_ALIGNMENT);

    return (panel);
}