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:layout.GridLayoutDemo.java

public void addComponentsToPane(final Container pane) {
    initGaps();//from  ww w .j a  v a2  s.  c  om
    final JPanel compsToExperiment = new JPanel();
    compsToExperiment.setLayout(experimentLayout);
    JPanel controls = new JPanel();
    controls.setLayout(new GridLayout(2, 3));

    //Set up components preferred size
    JButton b = new JButton("Just fake button");
    Dimension buttonSize = b.getPreferredSize();
    compsToExperiment.setPreferredSize(new Dimension((int) (buttonSize.getWidth() * 2.5) + maxGap,
            (int) (buttonSize.getHeight() * 3.5) + maxGap * 2));

    //Add buttons to experiment with Grid Layout
    compsToExperiment.add(new JButton("Button 1"));
    compsToExperiment.add(new JButton("Button 2"));
    compsToExperiment.add(new JButton("Button 3"));
    compsToExperiment.add(new JButton("Long-Named Button 4"));
    compsToExperiment.add(new JButton("5"));

    //Add controls to set up horizontal and vertical gaps
    controls.add(new Label("Horizontal gap:"));
    controls.add(new Label("Vertical gap:"));
    controls.add(new Label(" "));
    controls.add(horGapComboBox);
    controls.add(verGapComboBox);
    controls.add(applyButton);

    //Process the Apply gaps button press
    applyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //Get the horizontal gap value
            String horGap = (String) horGapComboBox.getSelectedItem();
            //Get the vertical gap value
            String verGap = (String) verGapComboBox.getSelectedItem();
            //Set up the horizontal gap value
            experimentLayout.setHgap(Integer.parseInt(horGap));
            //Set up the vertical gap value
            experimentLayout.setVgap(Integer.parseInt(verGap));
            //Set up the layout of the buttons
            experimentLayout.layoutContainer(compsToExperiment);
        }
    });
    pane.add(compsToExperiment, BorderLayout.NORTH);
    pane.add(new JSeparator(), BorderLayout.CENTER);
    pane.add(controls, BorderLayout.SOUTH);
}

From source file:ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    //Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);/*from   w ww .j  av a 2  s . c om*/
    patternList.addActionListener(this);

    //Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); //==
    // LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
}

From source file:biomine.bmvis2.pipeline.NodeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;//from   ww w . j  a  v a2  s.co  m
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableNodeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:com.db2eshop.gui.dialog.ConfirmCancelDialog.java

/**
 * <p>Constructor for ConfirmCancelDialog.</p>
 */// w  w  w .j  a  v a 2s.c om
public ConfirmCancelDialog() {
    layout = new MigLayout("fill", "", "[grow]rel[grow]");

    this.setMinimumSize(new Dimension(600, 300));
    setLayout(layout);

    contentPane = new JPanel();
    contentPane.setLayout(new MigLayout("fill"));

    scrollPane = new JScrollPane(contentPane);
    add(scrollPane, "grow, push,wrap");

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new MigLayout("fill"));

    confirmButton = new JButton("Confirm");
    buttonPane.add(confirmButton, "span,split 2,growx,push");
    confirmButton.addActionListener(this);

    cancelButton = new JButton("Cancel");
    buttonPane.add(cancelButton, "growx, push");
    cancelButton.addActionListener(this);

    add(buttonPane, "growx");//, south");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    addWindowListener(this);

    pack();

    ready = true;
}

From source file:moviedatas.MovieDatas.java

public JPanel createGlobalPanel() {
    SortPanelView sortFilterView = new SortPanelView();
    FilterPanelView filterPanelView = new FilterPanelView();

    JPanel sortPanel = sortFilterView.createSortPanel();
    JPanel filterPanel = filterPanelView.createFilterPanel();
    JPanel globalPanel = new JPanel();

    globalPanel.setLayout(new BoxLayout(globalPanel, BoxLayout.PAGE_AXIS));

    globalPanel.add(sortPanel);/* www  .  ja v a2 s  .  c  om*/
    globalPanel.add(filterPanel);

    return globalPanel;
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.StatText.java

@Override
public JPanel generateShortRTStats() {
    JPanel panel = new JPanel();
    panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
    panel.add(new JLabel(this.counter.globalDataset.getText()));
    panel.setToolTipText(generateRTStatsToolTip());
    return panel;
}

From source file:neironweb.Frame.java

public Frame() {
    super("neural network");
    //JPanel pane = new JPanel();

    setLayout(null);/*from ww w  .j a  va  2  s .  co m*/

    JPanel mailPanel = new JPanel();
    mailPanel.setLayout(null);
    mailPanel.setLocation(50, 30);
    mailPanel.setSize(300, 170);
    mailPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    JLabel mailLabel = new JLabel("e-mail:");
    mailLabel.setLocation(10, 10);
    mailLabel.setSize(50, 30);
    mailPanel.add(mailLabel);

    JLabel dirMailLabel = new JLabel("direct:");
    dirMailLabel.setLocation(10, 50);
    dirMailLabel.setSize(50, 30);
    mailPanel.add(dirMailLabel);

    JTextField mailField = new JTextField("mail@mail.ru");
    mailField.setSize(150, 30);
    mailField.setLocation(80, 10);
    mailPanel.add(mailField);

    JTextField textField = new JTextField("INBOX");
    textField.setLocation(80, 50);
    textField.setSize(150, 30);
    mailPanel.add(textField);

    JButton mailButton = new JButton("Analyze");
    mailButton.setLocation(80, 90);
    mailButton.setSize(150, 30);
    mailPanel.add(mailButton);

    //        JButton eduButton = new JButton("Start education");
    //        eduButton.setLocation(0, 50);
    //        eduButton.setSize(150, 30);
    //        buttonPanel.add(eduButton);

    XYSeries xyser = new XYSeries("");
    XYDataset xy = new XYSeriesCollection(xyser);
    JFreeChart jf = ChartFactory.createXYLineChart("Education", "X", "Y", xy);

    for (int i = 0; i < 100; i++)
        xyser.add(i, Math.cos(i));

    ChartPanel chartPanel = new ChartPanel(jf);
    chartPanel.setSize(700, 300);
    chartPanel.setLocation(50, 230);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    //        JPanel myChartPanel = new JPanel();        
    //        myChartPanel.setLayout(null);
    //        myChartPanel.setLocation(50, 230);
    //        myChartPanel.setSize(700, 300);
    //        myChartPanel
    //      myChartPanel.add(chartPanel);        

    setSize(800, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    //con.add(pane); 
    con.add(mailPanel);
    //con.add(myChartPanel);
    con.add(chartPanel);
    setVisible(true);

}

From source file:de.codesourcery.eve.skills.ui.components.impl.ByLabelFilterComponent.java

@Override
protected JPanel createPanel() {
    final JPanel result = new JPanel();

    result.setLayout(new GridBagLayout());
    result.setBorder(BorderFactory.createTitledBorder(title));

    // textfield/*from  w  w  w.j  ava  2  s .  c om*/
    this.nameField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            labelProvider.viewFilterChanged(getViewFilter());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            labelProvider.viewFilterChanged(getViewFilter());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            labelProvider.viewFilterChanged(getViewFilter());
        }
    });

    nameField.setColumns(20);
    result.add(nameField, constraints(0, 0).resizeHorizontally().useRelativeWidth().end());

    // button
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            nameField.setText("");
        }
    });
    result.add(clearButton, constraints(1, 0).noResizing().useRemainingWidth().end());

    return result;
}

From source file:CubicCurveMouse.java

public CubicCurveMouse() {
    super();/*from  ww w  . j  a va 2 s .c o m*/
    Container container = getContentPane();

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));

    panel.add(label);
    panel.add(label);

    panel.add(coords);

    container.add(panel, BorderLayout.SOUTH);

    canvas = new DrawingCanvas();
    container.add(canvas);

    addWindowListener(new WindowEventHandler());
    setSize(300, 300);
    setVisible(true);
}

From source file:bazaar4idea.ui.BzrTagDialog.java

/** Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 * @noinspection ALL//w w  w.j  a va 2 s .co  m
 */
private void $$$setupUI$$$() {
    contentPanel = new JPanel();
    contentPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
    final Spacer spacer1 = new Spacer();
    contentPanel.add(spacer1,
            new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
                    GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    hgRepositorySelectorComponent = new BzrRepositorySelectorComponent();
    contentPanel.add(hgRepositorySelectorComponent.$$$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 JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
    contentPanel.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("Tag name:");
    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));
    tagTxt = new JTextField();
    panel1.add(tagTxt,
            new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
                    new Dimension(150, -1), null, 0, false));
}