Example usage for javax.swing BoxLayout BoxLayout

List of usage examples for javax.swing BoxLayout BoxLayout

Introduction

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

Prototype

@ConstructorProperties({ "target", "axis" })
public BoxLayout(Container target, int axis) 

Source Link

Document

Creates a layout manager that will lay out components along the given axis.

Usage

From source file:Converter.java

/**
 * Create the ConversionPanels (one for metric, another for U.S.). I used
 * "U.S." because although Imperial and U.S. distance measurements are the
 * same, this program could be extended to include volume measurements, which
 * aren't the same.//from   w w  w  . j  a  v  a 2s  .c  om
 */
public Converter() {
    // Create Unit objects for metric distances, and then
    // instantiate a ConversionPanel with these Units.
    metricDistances[0] = new Unit("Centimeters", 0.01);
    metricDistances[1] = new Unit("Meters", 1.0);
    metricDistances[2] = new Unit("Kilometers", 1000.0);
    metricPanel = new ConversionPanel(this, "Metric System", metricDistances, dataModel);

    // Create Unit objects for U.S. distances, and then
    // instantiate a ConversionPanel with these Units.
    usaDistances[0] = new Unit("Inches", 0.0254);
    usaDistances[1] = new Unit("Feet", 0.305);
    usaDistances[2] = new Unit("Yards", 0.914);
    usaDistances[3] = new Unit("Miles", 1613.0);
    usaPanel = new ConversionPanel(this, "U.S. System", usaDistances, new FollowerRangeModel(dataModel));

    // Create a JPanel, and add the ConversionPanels to it.
    mainPane = new JPanel();
    mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        mainPane.setOpaque(true);
        mainPane.setBackground(new Color(255, 0, 0));
    }
    mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
    mainPane.add(metricPanel);
    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));
    mainPane.add(usaPanel);
    mainPane.add(Box.createGlue());
    resetMaxValues(true);
}

From source file:com.idealista.solrmeter.view.statistic.CacheHistoryPanel.java

/**
 * Constructor to be injected by Guice/*from  w  ww  .  j a v a  2  s. com*/
 * @param statistic
 */
@Inject
public CacheHistoryPanel(CacheHistoryStatistic statistic) {
    super();
    this.statistic = statistic;
    this.xyDataset = new DefaultXYDataset();
    this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    this.add(this.createLeftPanel());
    this.add(this.createChartPanel());
    this.setShowingSpecificData(false);//Show the hit ratio chart as default
}

From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java

private JPanel getJPanel11() {
    if (jPanel11 != null)
        return jPanel11;
    jPanel11 = new JPanel();
    jPanel11.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    jPanel11.setPreferredSize(new Dimension(340, 150));
    jPanel11.setLayout(new BoxLayout(jPanel11, BoxLayout.LINE_AXIS));
    jPanel11.add(getJScrollPane());//from   w w w. j  ava2s  .c  o m

    return jPanel11;
}

From source file:it.iit.genomics.cru.igb.bundles.mi.view.StructuresPanel.java

public StructuresPanel(IgbService service, String label) {

    super("MI Structures", "MI Structures", "Display structure", true);

    igbLogger = IGBLogger.getInstance(label);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    // Create hidden JmolFrame
    jmolFrame = new JFrame();

    jmolPanel = new JmolPanel();

    jmolPanel.setPreferredSize(new Dimension(500, 500));

    Box jmolBox = new Box(BoxLayout.Y_AXIS);
    Box jmolButtonBox = new Box(BoxLayout.X_AXIS);
    jmolFrame.add(jmolBox);/*ww w  .  j  a va 2s  .  c o m*/
    jmolBox.add(jmolPanel);
    jmolBox.add(jmolButtonBox);

    jmolButtonBox.add(new JLabel("Display type:"));

    ButtonGroup displayGroup = new ButtonGroup();
    JRadioButton cartoonButton = new JRadioButton(JMOL_DISPLAY_CARTOON);
    JRadioButton ballAndSticksButton = new JRadioButton(JMOL_DISPLAY_BALL_AND_STICK);

    JmolDisplayListener listener = new JmolDisplayListener();
    cartoonButton.addActionListener(listener);
    ballAndSticksButton.addActionListener(listener);

    displayGroup.add(cartoonButton);
    displayGroup.add(ballAndSticksButton);

    jmolButtonBox.add(cartoonButton);
    jmolButtonBox.add(ballAndSticksButton);

    ballAndSticksButton.setSelected(true);

    jmolFrame.pack();
    jmolFrame.setVisible(false);

    jmolButton.addActionListener(new JmolActionListener());
    jmolButton.setIcon(new ImageIcon(getClass().getResource("/jmol.jpg")));

    linkButton.addActionListener(new ExternalLinkActionListener());
    linkButton.setIcon(CommonUtils.getInstance().getIcon("16x16/actions/searchweb.png"));

    StructureTableModel model = new StructureTableModel(new ArrayList<StructureItem>(0));

    structureList = new StructureTable(model, service);
    structureList.setTableHeader(null);

    structureList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane structureListPane = new JScrollPane(structureList);

    add(structureListPane);
}

From source file:flexflux.analyses.result.TDRFBAResult.java

public void plot() {

    JPanel panel = new JPanel();
    JScrollPane sp = new JScrollPane(panel);
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    // one chart by entity

    Color[] colors = new Color[] { Color.RED, Color.GREEN, Color.BLUE };
    int index = 0;
    for (String s : entities) {

        XYSeriesCollection dataset = new XYSeriesCollection();

        XYSeries series = new XYSeries(s);

        for (Double time : times) {
            series.add(time, resultMap.get(time).get(s));
        }/*from  w  ww.  j  a  v a  2s .  co m*/

        final JFreeChart chart = ChartFactory.createXYLineChart(s, // chart
                // title
                "Time (h)", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // urls
        );

        chart.setBackgroundPaint(Color.white);

        XYPlot plot = (XYPlot) chart.getPlot();

        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeGridlinePaint(Color.GRAY);
        plot.setDomainGridlinePaint(Color.GRAY);

        plot.getRenderer().setSeriesPaint(0, colors[index % colors.length]);

        index++;

        ChartPanel chartPanel = new ChartPanel(chart);

        dataset.addSeries(series);

        panel.add(chartPanel);
        panel.add(new JSeparator());

    }

    Dimension d = panel.getComponent(0).getPreferredSize();
    d.height *= 2;

    sp.getViewport().setPreferredSize(d);

    JFrame frame = new JFrame("Time-dependant FBA results");

    frame.add(sp);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

From source file:mergedoc.ui.FileChooserField.java

/**
 * ??//from   www .ja v  a2s.com
 */
public FileChooserField() {

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    // ?
    int maxWidth = (int) ComponentFactory.createMaxDimension().getWidth();
    textField.setMaximumSize(new Dimension(maxWidth, 20));
    textField.setTransferHandler(new FileDropHandler());

    // ?
    ComponentFactory.ensureSize(button, 20, 18);
    button.setText("...");

    // ??
    CharsetSortedModel charsetModel = new CharsetSortedModel();
    charsetModel.add("EUC-JP");
    charsetModel.add("EUC-JP-LINUX");
    charsetModel.add("ISO-2022-JP");
    charsetModel.add("MS932");
    charsetModel.add("Shift_JIS");
    charsetModel.add("UTF-16");
    charsetModel.add("UTF-16BE");
    charsetModel.add("UTF-16LE");
    charsetModel.add("UTF-8");
    charsetModel.add(ENCODING_DEFAULT);
    charsetModel.fireAdded();

    // ???
    add(label);
    add(ComponentFactory.createSpacer(10, 0));
    add(textField);
    add(button);
    add(ComponentFactory.createSpacer(5, 0));
    add(combo);

    // ??
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int result = chooser.showOpenDialog(FileChooserField.this);
            if (result == JFileChooser.APPROVE_OPTION) {
                setFile(chooser.getSelectedFile());
                if (chooseListener != null) {
                    chooseListener.actionPerformed(e);
                }
            }
        }
    });
}

From source file:TableSelectionDemo.java

public TableSelectionDemo() {
    super(new BorderLayout());

    String[] columnNames = { "French", "Spanish", "Italian" };
    String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" },
            { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" },
            { "sept", "siete", "sette" } };

    table = new JTable(tableData, columnNames);
    listSelectionModel = table.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    table.setSelectionModel(listSelectionModel);
    JScrollPane tablePane = new JScrollPane(table);

    // Build control area (use default FlowLayout).
    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);//from  w w w  .j a v  a  2s. co  m
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    // Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    JPanel tableContainer = new JPanel(new GridLayout(1, 1));
    tableContainer.setBorder(BorderFactory.createTitledBorder("Table"));
    tableContainer.add(tablePane);
    tablePane.setPreferredSize(new Dimension(420, 130));
    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(250, 50));
    topHalf.setPreferredSize(new Dimension(200, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    // XXX: next line needed if bottomHalf is a scroll pane:
    // bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 110));
    splitPane.add(bottomHalf);
}

From source file:BoxAlignmentDemo.java

protected JPanel createLabelAndComponent(boolean doItRight) {
    JPanel pane = new JPanel();

    JComponent component = new JPanel();
    Dimension size = new Dimension(150, 100);
    component.setMaximumSize(size);/*from w ww  .j a v  a 2 s  . c  om*/
    component.setPreferredSize(size);
    component.setMinimumSize(size);
    TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER,
            TitledBorder.BELOW_TOP);
    border.setTitleColor(Color.black);
    component.setBorder(border);

    JLabel label = new JLabel("This is a JLabel");
    String title;
    if (doItRight) {
        title = "Matched";
        label.setAlignmentX(CENTER_ALIGNMENT);
    } else {
        title = "Mismatched";
    }

    pane.setBorder(BorderFactory.createTitledBorder(title));
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    pane.add(label);
    pane.add(component);
    return pane;
}

From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_vertical.java

public void setChart() {
    // update graph
    //   System.out.println("setChart called");

    graphPanel.removeAll();//www  .ja va2  s  .  com
    graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));

    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y));

    if (legendPanelOn) {
        JFreeChart chart2 = createLegendChart(createLegend(dataset));
        legendPanel = new ChartPanel(chart2, false);
        //legendPanel.setPreferredSize(new Dimension(CHART_SIZE_X,CHART_SIZE_Y*2/3));
    }

    graphPanel.add(chartPanel);
    JScrollPane legendPane = new JScrollPane(legendPanel);
    if (legendPanelOn) {
        legendPane.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 5));
        graphPanel.add(legendPane);
    }

    graphPanel.validate();

    // get the GRAPH panel to the front
    if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) {
        tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel));
        graphPanel.removeAll();
        graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));

        graphPanel.add(chartPanel);

        if (legendPanelOn) {
            legendPane = new JScrollPane(legendPanel);
            legendPane.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 5));
            graphPanel.add(legendPane);
        }
        graphPanel.validate();
    } else {
        graphPanel2.removeAll();
        chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 3));
        //legendPanel.setPreferredSize(new Dimension(CHART_SIZE_X*2/3,CHART_SIZE_Y*2/5));
        graphPanel2.add(chartPanel);
        if (legendPanelOn) {
            legendPane = new JScrollPane(legendPanel);
            legendPane.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 5));
            graphPanel2.add(legendPane);
        }
        graphPanel2.validate();
        summaryPanel.validate();
    }
}

From source file:es.emergya.ui.gis.popups.SDSDialog.java

public SDSDialog(Recurso r) {
    super();/*  w  w  w. j  a v  a  2  s .  c  o  m*/
    setAlwaysOnTop(true);
    setResizable(false);
    iconTransparente = LogicConstants.getIcon("48x48_transparente");
    iconEnviando = LogicConstants.getIcon("anim_enviando");
    destino = r;
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cancel.doClick();
        }
    });

    // setPreferredSize(new Dimension(400, 150));
    setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador());
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    JPanel base = new JPanel();

    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"),
            LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT);

    titleLabel.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(titleLabel);
    title.setOpaque(false);
    base.add(title);

    // Espacio para el mensaje
    sds = new JTextArea(7, 40);
    sds.setLineWrap(true);

    final JScrollPane sdsp = new JScrollPane(sds);

    sdsp.setOpaque(false);
    sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),
            i18n.getString("Admin.message") + "\t (0/" + maxChars + ")"));
    sds.setDocument(new PlainDocument() {
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= maxChars) {
                super.insertString(offs, str, a);
            }
        }
    });
    sds.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateChars(e);
        }

        private void updateChars(DocumentEvent e) {
            ((TitledBorder) sdsp.getBorder()).setTitle(
                    i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")");
            sdsp.repaint();
            send.setEnabled(!sds.getText().isEmpty());
            notification.setForeground(Color.WHITE);
            notification.setText("PLACEHOLDER");
        }
    });
    base.add(sdsp);

    // Area para mensajes
    JPanel notificationArea = new JPanel();

    notificationArea.setOpaque(false);
    notification = new JLabel("TEXT");
    notification.setForeground(Color.WHITE);
    notificationArea.add(notification);
    base.add(notificationArea);

    JPanel buttons = new JPanel();

    buttons.setOpaque(false);
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    send = new JButton(i18n.getString("Buttons.send"),
            LogicConstants.getIcon("ventanacontextual_button_enviarsds"));
    send.addActionListener(this);
    send.setEnabled(false);
    buttons.add(send);
    buttons.add(Box.createHorizontalGlue());
    progressIcon = new JLabel(iconTransparente);
    buttons.add(progressIcon);
    buttons.add(Box.createHorizontalGlue());
    cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    base.add(buttons);
    getContentPane().add(base);
    pack();

    int x;
    int y;
    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent arg0) {
            deleteErrorMessage();
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
            deleteErrorMessage();
        }

        private void deleteErrorMessage() {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    if (bandejaSalida != null) {
                        MessageGenerator.remove(bandejaSalida.getId());
                    }

                    bandejaSalida = null;

                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    SDSDialog.this.sds.setText("");
                    SDSDialog.this.sds.setEnabled(true);
                    SDSDialog.this.sds.repaint();
                    SDSDialog.this.progressIcon.setIcon(iconTransparente);
                    SDSDialog.this.progressIcon.repaint();
                    SDSDialog.this.notification.setText("");
                    SDSDialog.this.notification.repaint();
                }
            };

            sw.execute();
        }
    });
}