Example usage for java.awt GridBagConstraints BOTH

List of usage examples for java.awt GridBagConstraints BOTH

Introduction

In this page you can find the example usage for java.awt GridBagConstraints BOTH.

Prototype

int BOTH

To view the source code for java.awt GridBagConstraints BOTH.

Click Source Link

Document

Resize the component both horizontally and vertically.

Usage

From source file:Main.java

public Main() {
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    getContentPane().setLayout(layout);/* ww  w . j av a 2  s .co  m*/
    constraints.anchor = GridBagConstraints.WEST;
    JLabel l1 = new JLabel("First Name:");
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(l1, constraints);
    getContentPane().add(l1);

    JTextField t1 = new JTextField();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(5, 5, 5, 5);
    layout.setConstraints(t1, constraints);
    getContentPane().add(t1);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(700, 500);
}

From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java

public static int select(String title, String message, String description, List<Option> options,
        int defaultOption) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);/*from  w  w  w.  j  ava 2  s .  c  om*/
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1));

    JButton defaultBtn = null;

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    // All the options
    cLabel.ipadx = 10;
    cLabel.ipady = 10;
    cLabel.insets = new Insets(5, 15, 0, 15);
    for (int i = 0; i < options.size(); i++) {
        cLabel.gridy++;

        final Option o = options.get(i);
        final JButton btn = new JButton(
                "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"),
                MessageDialog.loadIcon(o.icon));
        if (StringUtils.isNotBlank(o.info)) {
            btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>"));
        }

        btn.setHorizontalAlignment(AbstractButton.LEADING);
        btn.setVerticalTextPosition(AbstractButton.CENTER);
        btn.setHorizontalTextPosition(AbstractButton.TRAILING);

        final int myAnswer = i;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                result.set(myAnswer);
                dialog.setVisible(false);
            }
        });

        root.add(btn, cLabel);
        if (i == defaultOption) {
            dialog.getRootPane().setDefaultButton(btn);
            defaultBtn = btn;
        }
    }

    final Icon icon = MessageDialog.loadIcon();
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2 + options.size();
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    final JButton close = new JButton("Cancel");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result.set(-1);
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2 + options.size();
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(15, 5, 5, 5);

    root.add(close, cClose);
    if (defaultOption < 0) {
        dialog.getRootPane().setDefaultButton(close);
        defaultBtn = close;
    }

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    defaultBtn.requestFocusInWindow();

    dialog.setVisible(true);
    dialog.dispose();

    return result.get();
}

From source file:org.onehippo.cms7.launcher.LoggingPanel.java

LoggingPanel() {

    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();

    loggingDocument = new PlainDocument();

    constraints.gridx = 0;/*from  w ww.  j a  va2  s  . c  o  m*/
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridwidth = 1;
    constraints.insets = new Insets(2, 4, 2, 2);
    constraints.fill = GridBagConstraints.BOTH;
    final JLabel infoMessge = new JLabel("Application server log, most recent line at the top");
    add(infoMessge, constraints);

    loggingTextArea = new JTextArea(loggingDocument);
    loggingTextArea.setEditable(false);
    loggingScrollPane = new JScrollPane(loggingTextArea);
    loggingScrollPane.setPreferredSize(new Dimension(600, 200));
    loggingScrollPane.setAutoscrolls(true);

    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.fill = GridBagConstraints.CENTER;
    add(loggingScrollPane, constraints);
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

private static GridBagConstraints getDefaultGridBagConstraints() {
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;/*from   w w  w  .  j  a va 2 s .  c o  m*/
    gridBagConstraints.weighty = 1.0;
    return gridBagConstraints;
}

From source file:events.TreeExpandEventDemo.java

public TreeExpandEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;//from  w  ww  . j av a  2  s  . c o m
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    demoArea = new DemoArea();
    gridbag.setConstraints(demoArea, c);
    add(demoArea);

    c.insets = new Insets(0, 0, 0, 0);
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:fll.scheduler.ChooseChallengeDescriptor.java

private void initComponents() {
    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1;// w ww .ja v a  2s . c om
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    final JTextArea instructions = new JTextArea(
            "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.",
            3, 40);
    instructions.setEditable(false);
    instructions.setWrapStyleWord(true);
    instructions.setLineWrap(true);
    getContentPane().add(instructions, gbc);

    gbc = new GridBagConstraints();
    mCombo = new JComboBox<DescriptionInfo>();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(mCombo, gbc);
    mCombo.setRenderer(new DescriptionInfoRenderer());
    mCombo.setEditable(false);
    final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo();
    for (final DescriptionInfo info : descriptions) {
        mCombo.addItem(info);
    }

    mFileField = new JLabel();
    gbc = new GridBagConstraints();
    gbc.weightx = 1;
    getContentPane().add(mFileField, gbc);

    final JButton chooseButton = new JButton("Choose File");
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(chooseButton, gbc);
    chooseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mFileField.setText(null);

            final JFileChooser fileChooser = new JFileChooser();
            final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" });
            fileChooser.setFileFilter(filter);

            final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File selectedFile = fileChooser.getSelectedFile();
                mFileField.setText(selectedFile.getAbsolutePath());
            }
        }
    });

    final Box buttonPanel = new Box(BoxLayout.X_AXIS);
    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    getContentPane().add(buttonPanel, gbc);

    buttonPanel.add(Box.createHorizontalGlue());
    final JButton ok = new JButton("Ok");
    buttonPanel.add(ok);
    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {

            // use the selected description if nothing is entered in the file box
            final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex());
            if (null != descriptionInfo) {
                mSelected = descriptionInfo.getURL();
            }

            final String text = mFileField.getText();
            if (!StringUtils.isEmpty(text)) {
                final File file = new File(text);
                if (file.exists()) {
                    try {
                        mSelected = file.toURI().toURL();
                    } catch (final MalformedURLException e) {
                        throw new FLLInternalException("Can't turn file into URL?", e);
                    }
                }
            }

            setVisible(false);
        }
    });

    final JButton cancel = new JButton("Cancel");
    buttonPanel.add(cancel);
    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent ae) {
            mSelected = null;
            setVisible(false);
        }
    });

    pack();
}

From source file:org.mbs3.juniuploader.gui.pnlAbout.java

private void initGUI() {
    try {/*from   w  ww.  j  av  a 2  s.  c o  m*/
        GridBagLayout thisLayout = new GridBagLayout();
        thisLayout.rowWeights = new double[] { 0.0, 0.0, 0.1, 0.0, 0.0, 0.1, 0.0 };
        thisLayout.rowHeights = new int[] { 7, 25, 20, 8, 23, 20, 6 };
        thisLayout.columnWeights = new double[] { 0.0, 0.1, 0.1 };
        thisLayout.columnWidths = new int[] { 11, 7, 20 };
        this.setLayout(thisLayout);
        this.setPreferredSize(new java.awt.Dimension(626, 368));
        {
            lblImage1 = new JLabel();
            File fImage = new File("logo1.gif");
            if (fImage != null & fImage.canRead()) {
                ImageIcon i = new ImageIcon(fImage.getAbsolutePath());
                lblImage1.setIcon(i);
            }
            this.add(lblImage1, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
        {
            lblLogo1Desc = new JLabel();
            this.add(getLblLogo1Desc(), new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            lblLogo1Desc.setText("Logo2:");
        }
        {
            jLabel1 = new JLabel();
            this.add(jLabel1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            jLabel1.setText("Logo1:");
        }
        {
            lblImage2 = new JLabel();
            File fImage2 = new File("logo2.gif");
            if (fImage2 != null & fImage2.canRead()) {
                ImageIcon i = new ImageIcon(fImage2.getAbsolutePath());
                lblImage2.setIcon(i);
            }

            this.add(lblImage2, new GridBagConstraints(1, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
    } catch (Exception ex) {
        log.error("initGui() exception", ex);
    }
}

From source file:loadmaprenderer.ResultDisplayChart.java

public void drawChart(List<ResultDataPair> values, String chartTitle, String dataTitle, double average,
        boolean setAverage) {
    this.removeAll();
    this.setLayout(new GridBagLayout());
    GridBagConstraints gbc;/* w w  w.  j  av a  2 s.  co m*/
    if (values == null || values.isEmpty() || allZero(values)) {
        if (values == null || values.isEmpty())
            label.setText("No Selection or No Result Data");
        else
            label.setText("ALL ZERO");
        this.setLayout(new GridBagLayout());
        this.add(label);
        return;
    }
    if (dataLine != null)
        dataLine.clear();
    if (averageLine != null)
        averageLine.clear();
    if (!setAverage)
        average = getAverage(values);
    XYDataset dataset = makeChartDataset(values, dataTitle, average);
    chart = makeChart(dataset, chartTitle, dataTitle);
    ChartPanel cp = new ChartPanel(chart);

    gbc = setGbc(new Insets(0, 0, 0, 0), GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 1, 1, 1.0,
            1.0);
    this.add(cp, gbc);
    //this.setPreferredSize(new Dimension(500,150));
}

From source file:tl.lib.dataCollection.gui.MultipleChartsPanel.java

public MultipleChartsPanel(_CollectionGUIScenario scenario, String label, String description) {
    super(new GridBagLayout());
    this.charts = new Hashtable<Integer, _ChartPanel>();
    this.scenario = scenario;
    this.description = description;
    this.label = label;
    grid = new GridBagConstraints();
    grid.weighty = 1;//from w  ww . ja  v a  2 s  . c  om
    grid.weightx = 1;
    grid.anchor = GridBagConstraints.PAGE_START;
    grid.fill = GridBagConstraints.BOTH;
}

From source file:components.TextDemo.java

public TextDemo() {
    super(new GridBagLayout());

    textField = new JTextField(20);
    textField.addActionListener(this);

    textArea = new JTextArea(5, 20);
    textArea.setEditable(false);//w w w.j  av  a 2s  .c  om
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Add Components to this panel.
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = GridBagConstraints.REMAINDER;

    c.fill = GridBagConstraints.HORIZONTAL;
    add(textField, c);

    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    add(scrollPane, c);
}