Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:events.ListSelectionDemo.java

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

    String[] listData = { "one", "two", "three", "four", "five", "six", "seven" };
    String[] columnNames = { "French", "Spanish", "Italian" };
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);//  ww  w  . j  a va  2s  . c o  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));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    //topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 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, 135));
    splitPane.add(bottomHalf);
}

From source file:bazaar4idea.ui.BzrPullDialog.java

/** Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 * @noinspection ALL/*from www  . j a  v  a  2 s.  c  o m*/
 */
private void $$$setupUI$$$() {
    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
    hgRepositorySelector = new BzrRepositorySelectorComponent();
    mainPanel.add(hgRepositorySelector.$$$getRootComponent$$$(),
            new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
                    null, 0, false));
    final Spacer spacer1 = new Spacer();
    mainPanel.add(spacer1,
            new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
                    GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    final JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
    mainPanel.add(panel1,
            new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
                    null, 0, false));
    final JLabel label1 = new JLabel();
    label1.setText("Pull From:");
    panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
            GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    final Spacer spacer2 = new Spacer();
    panel1.add(spacer2,
            new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
    sourceTxt = new JTextField();
    panel1.add(sourceTxt,
            new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                    false));
}

From source file:AffineTransformApp.java

public AffineTransformApp() {
    super();// ww w.  ja v  a2  s .c om
    Container container = getContentPane();

    displayPanel = new DisplayPanel();
    container.add(displayPanel);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 4, 5, 5));
    scaleXval = new JComboBox(scaleValues);
    scaleXval.setSelectedItem("1.00");
    scaleXval.addActionListener(new ComboBoxListener());
    scaleYval = new JComboBox(scaleValues);
    scaleYval.setSelectedItem("1.00");
    scaleYval.addActionListener(new ComboBoxListener());

    shearXval = new JComboBox(shearValues);
    shearXval.setSelectedItem("0.00");
    shearXval.addActionListener(new ComboBoxListener());
    shearYval = new JComboBox(shearValues);
    shearYval.setSelectedItem("0.00");
    shearYval.addActionListener(new ComboBoxListener());

    panel.add(new JLabel("Scale X value:"));
    panel.add(scaleXval);
    panel.add(new JLabel("Scale Y value:"));
    panel.add(scaleYval);
    panel.add(new JLabel("Shear X value:"));
    panel.add(shearXval);
    panel.add(new JLabel("Shear Y value:"));
    panel.add(shearYval);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 10);
    setVisible(true);
}

From source file:com.github.woonsan.commons.scxml.examples.stopwatch.StopWatchFrame.java

private void initUI() {
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    setContentPane(mainPanel);//www.j  a  v  a 2  s  . c  om

    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new FlowLayout());
    displayLabel = new JLabel("0:00:00,000");
    contentPanel.add(displayLabel, BorderLayout.CENTER);

    mainPanel.add(contentPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    startButton = createButton("START", "Start");
    buttonPanel.add(startButton);

    stopButton = createButton("STOP", "Stop");
    stopButton.setEnabled(false);
    buttonPanel.add(stopButton);

    resetButton = createButton("RESET", "Reset");
    resetButton.setEnabled(false);
    buttonPanel.add(resetButton);

    mainPanel.add(buttonPanel, BorderLayout.SOUTH);

    pack();

    setLocation(200, 200);
    setSize(260, 80);

    setResizable(true);
    setVisible(true);

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Timer displayTimer = new Timer();
    displayTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            displayLabel.setText(stopWatch.getDisplay());
        }
    }, 100, 100);
}

From source file:TabbedPaneDemo.java

protected JComponent makeTextPanel(String text) {
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(JLabel.CENTER);
    panel.setLayout(new GridLayout(1, 1));
    panel.add(filler);//  w  w w  . j a  v  a2 s.c om
    return panel;
}

From source file:CombineApp.java

public CombineApp() {
    super("TBandCombineOp");
    Container container = getContentPane();

    displayPanel = new CombinePanel();
    container.add(displayPanel);//from   w ww  .  ja  va 2  s  .c o m

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, 2));
    panel.setBorder(new TitledBorder("Click a Button to Perform the Associated Operation and Reset..."));

    redBandButton = new JButton("Show Red Band");
    redBandButton.addActionListener(new ButtonListener());
    greenBandButton = new JButton("Show Green Band");
    greenBandButton.addActionListener(new ButtonListener());
    blueBandButton = new JButton("Show Blue Band");
    blueBandButton.addActionListener(new ButtonListener());
    inverseBandButton = new JButton("Invert All Bands");
    inverseBandButton.addActionListener(new ButtonListener());
    middleBandButton = new JButton("Average Each Band");
    middleBandButton.addActionListener(new ButtonListener());

    resetButton = new JButton("Reset");
    resetButton.addActionListener(new ButtonListener());

    panel.add(redBandButton);
    panel.add(blueBandButton);
    panel.add(greenBandButton);
    panel.add(inverseBandButton);
    panel.add(middleBandButton);
    panel.add(resetButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    setSize(displayPanel.getWidth(), displayPanel.getHeight());
    setVisible(true);
}

From source file:gda.util.userOptions.UserOptionsDialog.java

@SuppressWarnings("rawtypes")
private JPanel makePane() {
    JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

    Iterator<Map.Entry<String, UserOption>> iter = options.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<String, UserOption> entry = iter.next();
        UserOption option = entry.getValue();
        if (option.defaultValue instanceof Boolean && option.description instanceof String) {
            JCheckBox box = new JCheckBox((String) option.description);
            box.setSelected((Boolean) option.value);
            box.setAlignmentX(Component.LEFT_ALIGNMENT);
            box.setAlignmentY(Component.LEFT_ALIGNMENT);
            components.put(entry.getKey(), box);
            pane.add(box);/*w w  w.j  av a2 s.co  m*/
        }
    }
    return pane;
}

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

private JPanel getMainPanel() {
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    //Status box.
    mainPanel.add(getStatusEditorPanel());

    //Comment box.
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(Box.createHorizontalGlue());
    comment = new JTextArea();
    p.add(comment);/*  w  ww . ja v a 2s . c o m*/
    p.add(Box.createHorizontalGlue());
    mainPanel.add(p);

    //Button box.        
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(Box.createHorizontalGlue());
    JButton OKButton = new JButton("Update status");
    OKButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                updateStatus();
                dispose();
            } catch (Exception ex) {
                LOG.error(ex.getMessage(), ex);
                DialogUtils.displayException("Error", ex.getMessage(), ex);
            }
        }
    });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(OKButton);
    p.add(cancelButton);
    p.add(Box.createHorizontalGlue());
    mainPanel.add(p);

    return mainPanel;
}

From source file:Main.java

public Main() {
    setSize(500, 340);//from w  w  w.j  ava  2s .co  m

    Date currentDate = new Date();
    calendar.setTime(currentDate);

    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(4, 1));

    JPanel p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Selected Date"));
    dateLabel = new JLabel(dateFormat.format(currentDate) + "     ");
    dateLabel.setFont(new Font("Arial", Font.BOLD, 24));
    p.add(dateLabel);
    p1.add(p);

    yearSlider.setPaintLabels(true);
    yearSlider.setMajorTickSpacing(5);
    yearSlider.setMinorTickSpacing(1);
    yearSlider.setPaintTicks(true);
    DateListener lst = new DateListener();
    yearSlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Year"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(yearSlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    String[] months = (new DateFormatSymbols()).getShortMonths();
    hashTable = new Hashtable(12);
    for (int i = 0; i < 12; i++)
        hashTable.put(new Integer(i + 1), new JLabel(months[i], JLabel.CENTER));
    monthSlider.setLabelTable(hashTable);
    monthSlider.setPaintLabels(true);
    monthSlider.setMajorTickSpacing(1);
    monthSlider.setPaintTicks(true);
    monthSlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Month"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(monthSlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    daySlider = new JSlider(JSlider.HORIZONTAL, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH));
    daySlider.setPaintLabels(true);
    daySlider.setMajorTickSpacing(5);
    daySlider.setMinorTickSpacing(1);
    daySlider.setPaintTicks(true);
    daySlider.addChangeListener(lst);

    p = new JPanel();
    p.setBorder(new TitledBorder(new EtchedBorder(), "Day"));
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p.add(daySlider);
    p.add(Box.createRigidArea(RIGID_DIMENSION));
    p1.add(p);

    getContentPane().add(p1, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    enableEvents(ComponentEvent.COMPONENT_RESIZED);
    setVisible(true);
}

From source file:net.sf.maltcms.chromaui.normalization.spi.actions.OpenPeakGroupBoxPlot.java

@Override
public void actionPerformed(ActionEvent ev) {
    IChromAUIProject project = Utilities.actionsGlobalContext().lookup(IChromAUIProject.class);
    if (project != null && !context.isEmpty()) {
        IPeakNormalizer normalizer = NormalizationDialog
                .getPeakNormalizer(context.get(0).getPeakGroupContainer());
        if (normalizer == null) {
            return;
        }// w w  w .jav  a  2 s  .  c o  m
        PeakGroupBoxPlotTopComponent pgbpt = new PeakGroupBoxPlotTopComponent();
        PeakGroupBoxPlot pgbp = new PeakGroupBoxPlot(project, context, normalizer);
        JPanel bg = new JPanel();
        BoxLayout bl = new BoxLayout(bg, BoxLayout.Y_AXIS);
        bg.setLayout(bl);
        for (JFreeChart chart : pgbp.createChart()) {
            ChartPanel cp = new ContextAwareChartPanel(chart);
            bg.add(cp);
        }

        JScrollPane jsp = new JScrollPane(bg);
        pgbpt.add(jsp, BorderLayout.CENTER);
        IRegistry registry = Lookup.getDefault().lookup(IRegistryFactory.class).getDefault();
        for (IPeakGroupDescriptor pgd : context) {
            registry.registerTopComponentFor(pgd, pgbpt);
        }
        pgbpt.open();
        pgbpt.requestActive();
    } else {
        Logger.getLogger(getClass().getName()).warning("No IChromAUI project is in lookup!");
    }
}