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:VoteDialog.java

private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton) {
    int numChoices = radioButtons.length;
    JPanel box = new JPanel();
    JLabel label = new JLabel(description);

    box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
    box.add(label);/*from   w w w  .  ja v  a 2s. c o m*/

    for (int i = 0; i < numChoices; i++) {
        box.add(radioButtons[i]);
    }

    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout());
    pane.add(box, BorderLayout.NORTH);
    pane.add(showButton, BorderLayout.SOUTH);
    System.out.println("returning pane");
    return pane;
}

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

/**
 * Creates the UI panel containing all of the fields necessary to upload
 * the current session data to the web service
 *///from  w  w  w .ja  va 2s  .  c  o m
private void createSetupPane() {
    this.setupPanel = new JPanel();
    this.setupPanel.setLayout(new BorderLayout());
    this.setupPanel.setBackground(Color.white);

    try {
        String data = IOUtils.toString(LoginDialog.class.getResourceAsStream("/export2.html"));
        data = data.replace("{LIST}", formatWitnessList());
        JLabel txt = new JLabel(data);
        this.setupPanel.add(txt, BorderLayout.NORTH);
    } catch (IOException e) {
        // dunno. not much that can be done!
    }

    // ugly layout code to follow. avert your eyes
    JPanel data = new JPanel();
    data.setLayout(new BorderLayout());
    data.setBackground(Color.white);

    JPanel names = new JPanel();
    names.setLayout(new BoxLayout(names, BoxLayout.Y_AXIS));
    names.setBackground(Color.white);
    JLabel l = new JLabel("Name:", SwingConstants.RIGHT);
    l.setPreferredSize(new Dimension(100, 20));
    l.setMaximumSize(new Dimension(100, 20));
    l.setAlignmentX(RIGHT_ALIGNMENT);
    names.add(l);
    names.add(Box.createVerticalStrut(5));

    JLabel l2 = new JLabel("Description:", SwingConstants.RIGHT);
    l2.setPreferredSize(new Dimension(100, 20));
    l2.setMaximumSize(new Dimension(100, 20));
    l2.setAlignmentX(RIGHT_ALIGNMENT);
    names.add(l2);
    data.add(names, BorderLayout.WEST);

    JPanel edits = new JPanel();
    edits.setBackground(Color.white);
    edits.setLayout(new BoxLayout(edits, BoxLayout.Y_AXIS));
    this.nameEdit = new JTextField();
    this.nameEdit.setPreferredSize(new Dimension(200, 22));
    this.nameEdit.setMaximumSize(new Dimension(200, 22));
    File saveFile = this.juxtaFrame.getSession().getSaveFile();
    if (saveFile == null) {
        this.nameEdit.setText("new_session");
    } else {
        String name = saveFile.getName();
        this.nameEdit.setText(name.substring(0, name.lastIndexOf('.')));
    }
    edits.add(this.nameEdit);

    this.descriptionEdit = new JTextArea(3, 0);
    this.descriptionEdit.setLineWrap(true);
    this.descriptionEdit.setWrapStyleWord(true);

    JScrollPane sp = new JScrollPane(this.descriptionEdit);
    sp.setPreferredSize(new Dimension(194, 60));
    sp.setMaximumSize(new Dimension(194, 300));
    edits.add(Box.createVerticalStrut(4));
    edits.add(sp);

    data.add(edits, BorderLayout.CENTER);

    this.setupPanel.add(data, BorderLayout.SOUTH);
}

From source file:edu.ku.brc.specify.ui.treetables.TreeDefinitionEditor.java

/**
* @param isEditMode whether to enable editing.
*//*from   ww  w  .  j  av a  2s.c  o  m*/
protected void initUI() {
    this.setLayout(new BorderLayout());

    Dimension horizSpacer = new Dimension(5, 0);

    statusBar = UIRegistry.getStatusBar();

    // create north panel
    titlePanel = new JPanel();
    titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.LINE_AXIS));

    defNameLabel = createLabel(""); //$NON-NLS-1$

    titlePanel.add(Box.createHorizontalGlue());
    titlePanel.add(defNameLabel);
    titlePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 0));

    if (isEditMode) {
        //editDefButton = createButton(editIcon);
        editDefButton = UIHelper.createIconBtn("EditIcon", "TTV_EDIT_TREDEF_TITLE", new ActionListener() //$NON-NLS-1$ //$NON-NLS-2$
        {
            public void actionPerformed(ActionEvent ae) {
                showDefEditDialog(displayedDef);
            }
        });
        editDefButton.setEnabled(true);

        // add north panel widgets
        titlePanel.add(Box.createRigidArea(horizSpacer));
        titlePanel.add(editDefButton);

    } else {
        editDefButton = null;
    }
    titlePanel.add(Box.createHorizontalGlue());

    if (isEditMode) {
        // create south panel
        ActionListener deleteAction = new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                deleteItem(defItemsTable.getSelectedRow());
            }
        };
        ActionListener newItemAction = new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                newItem(defItemsTable.getSelectedRow());
            }
        };

        ActionListener editItemAction = new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                editTreeDefItem(defItemsTable.getSelectedRow());
            }
        };

        edaPanel = new EditDeleteAddPanel(editItemAction, deleteAction, newItemAction, "TTV_EDIT_TDI", //$NON-NLS-1$
                "TTV_DEL_TDI", "TTV_NEW_TDI"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:instance.gui.InstanceGUI.java

private void createDataSection() {
    dataSection = new JPanel();
    dataSection.setBorder(BorderFactory.createTitledBorder("Data block(s)"));
    dataSection.setLayout(new BoxLayout(dataSection, BoxLayout.Y_AXIS));

    createNumberOfRequestsLabel(dataSection);
    createCurrentTransfers(dataSection);
    createRequestQueue(dataSection);//w  w  w.j av a  2  s.co m
    createDataBlockTable(dataSection);

    infoTab.add(dataSection);
}

From source file:SoundPlayer.java

public SoundPlayer(File f, boolean isMidi) throws IOException, UnsupportedAudioFileException,
        LineUnavailableException, MidiUnavailableException, InvalidMidiDataException {
    if (isMidi) { // The file is a MIDI file
        midi = true;//from   ww  w  .ja va  2s  .c om
        // First, get a Sequencer to play sequences of MIDI events
        // That is, to send events to a Synthesizer at the right time.
        sequencer = MidiSystem.getSequencer(); // Used to play sequences
        sequencer.open(); // Turn it on.

        // Get a Synthesizer for the Sequencer to send notes to
        Synthesizer synth = MidiSystem.getSynthesizer();
        synth.open(); // acquire whatever resources it needs

        // The Sequencer obtained above may be connected to a Synthesizer
        // by default, or it may not. Therefore, we explicitly connect it.
        Transmitter transmitter = sequencer.getTransmitter();
        Receiver receiver = synth.getReceiver();
        transmitter.setReceiver(receiver);

        // Read the sequence from the file and tell the sequencer about it
        sequence = MidiSystem.getSequence(f);
        sequencer.setSequence(sequence);
        audioLength = (int) sequence.getTickLength(); // Get sequence length
    } else { // The file is sampled audio
        midi = false;
        // Getting a Clip object for a file of sampled audio data is kind
        // of cumbersome. The following lines do what we need.
        AudioInputStream ain = AudioSystem.getAudioInputStream(f);
        try {
            DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat());
            clip = (Clip) AudioSystem.getLine(info);
            clip.open(ain);
        } finally { // We're done with the input stream.
            ain.close();
        }
        // Get the clip length in microseconds and convert to milliseconds
        audioLength = (int) (clip.getMicrosecondLength() / 1000);
    }

    // Now create the basic GUI
    play = new JButton("Play"); // Play/stop button
    progress = new JSlider(0, audioLength, 0); // Shows position in sound
    time = new JLabel("0"); // Shows position as a #

    // When clicked, start or stop playing the sound
    play.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (playing)
                stop();
            else
                play();
        }
    });

    // Whenever the slider value changes, first update the time label.
    // Next, if we're not already at the new position, skip to it.
    progress.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int value = progress.getValue();
            // Update the time label
            if (midi)
                time.setText(value + "");
            else
                time.setText(value / 1000 + "." + (value % 1000) / 100);
            // If we're not already there, skip there.
            if (value != audioPosition)
                skip(value);
        }
    });

    // This timer calls the tick() method 10 times a second to keep
    // our slider in sync with the music.
    timer = new javax.swing.Timer(100, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tick();
        }
    });

    // put those controls in a row
    Box row = Box.createHorizontalBox();
    row.add(play);
    row.add(progress);
    row.add(time);

    // And add them to this component.
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    this.add(row);

    // Now add additional controls based on the type of the sound
    if (midi)
        addMidiControls();
    else
        addSampledControls();
}

From source file:org.jdal.swing.PageableTable.java

/**
 * Create the right menu bar//from w w  w .j a  va2  s  .c  o  m
 */
private void createMenu() {
    rightMenuBar = new JMenuBar();
    rightMenuBar.setLayout(new BoxLayout(rightMenuBar, BoxLayout.PAGE_AXIS));
    rightMenuBar.setMargin(new Insets(0, 0, 0, 0));
    // Add Visibility menu
    JMenu menu = new JMenu();
    menu.setMargin(new Insets(0, 0, 0, 0));
    menu.setIcon(visibilityMenuIcon);
    menu.setMaximumSize(new Dimension(50, 50));
    visibilityBox = new VisibilityBox(columnDescriptors);
    menu.add(visibilityBox);
    menu.getPopupMenu().addPopupMenuListener(new VisibilityPopupListener());
    JMenuItem okMenuItem = new JMenuItem(new OkVisibilityAction());
    JMenuItem cancelMenuItem = new JMenuItem(new CancelVisibilityAction());
    menu.addSeparator();
    menu.add(okMenuItem);
    menu.add(cancelMenuItem);
    rightMenuBar.add(menu);
    JMenu prefsMenu = new JMenu();
    prefsMenu.setMargin(new Insets(0, 0, 0, 0));
    prefsMenu.setIcon(userMenuIcon);
    prefsMenu.setMaximumSize(new Dimension(50, 50));
    prefsMenu.add(new JMenuItem(new LoadPreferencesAction(this, messageSource
            .getMessage("PageableTable.loadPreferences", null, "Load Preferences", Locale.getDefault()))));
    prefsMenu.add(new JMenuItem(new SavePreferencesAction(this, messageSource
            .getMessage("PageableTable.savePreferences", null, "Save Preferences", Locale.getDefault()))));
    rightMenuBar.add(prefsMenu);
    rightMenuBar.add(Box.createVerticalGlue());
    // Add menu bar to right
    add(rightMenuBar, BorderLayout.EAST);
}

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

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

    graphPanel.removeAll();//from  w w w  .j a va 2s  .  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:diet.gridr.g5k.gui.ClusterInfoPanel.java

/**
 * This method initializes jPanel/*  ww  w. j  a v a  2  s. c om*/
 *
 * @return javax.swing.JPanel
 */
private JPanel getJPanel() {
    if (jPanel == null) {
        jPanel = new JPanel();
        jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
        jPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        jPanel.add(getSelectionChartPanel());
        jPanel.add(Box.createVerticalStrut(10));
        jPanel.add(getCardPanel());
        jPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    }
    return jPanel;
}

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

private void addCapa(final GpxLayer layer) {
    final JPanel capaP = new JPanel();
    capaP.setOpaque(false);// w  ww . ja  v  a  2 s.  com
    layer.visible = true;
    mapView.addLayer(layer, false, capasActuales.size());
    capasActuales.add(layer);
    capaP.setLayout(new BoxLayout(capaP, BoxLayout.X_AXIS));

    final JCheckBox capa = new JCheckBox(layer.getAssociatedFile().getAbsolutePath());
    capa.setSelected(layer.visible);
    capa.setBackground(Color.WHITE);
    capa.setToolTipText(i18n.getString("window.gpx.checkbox.show.tooltip"));
    capa.setActionCommand(layer.name);
    capa.addActionListener(this);
    capaP.add(capa);
    capaP.add(Box.createHorizontalGlue());
    JButton eliminar = new JButton(LogicConstants.getIcon("button_delone"));
    eliminar.setToolTipText(i18n.getString("window.gpx.button.delete.tooltip"));
    eliminar.setBorderPainted(false);
    eliminar.setContentAreaFilled(false);

    capaP.add(eliminar);
    eliminar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mapView.removeLayer(layer);
            mapView.repaint();
            capasGpx.remove(capaP);
            capasGpx.updateUI();
            capasActuales.remove(layer);
        }
    });

    capasGpx.add(capaP);
    capasGpx.updateUI();
}

From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java

protected void initMixPanel() {
    sliderPanel2 = new JPanel();
    sliderPanel2.setLayout(new BoxLayout(sliderPanel2, BoxLayout.Y_AXIS));

    graphPanel2 = new JPanel();
    //      graphPanel2.setLayout(new BoxLayout(graphPanel2, BoxLayout.Y_AXIS));

    mixPanel = new JPanel(new BorderLayout());
    //      resetChart();

    setMixPanel();// w w w.  ja  v  a 2  s. c  o  m
}