Example usage for java.awt GridBagConstraints RELATIVE

List of usage examples for java.awt GridBagConstraints RELATIVE

Introduction

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

Prototype

int RELATIVE

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

Click Source Link

Document

Specifies that this component is the next-to-last component in its column or row ( gridwidth , gridheight ), or that this component be placed next to the previously added component ( gridx , gridy ).

Usage

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendMaxMutationsPerIndividualSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {//from www .j a v a2 s.  c o m
    SpinnerModel maxMutationsPerIndividualModel = new SpinnerNumberModel(maxMutationsPerIndividualInitial,
            MAX_MUTATION_MIN, MAX_MUTATION_MAX, MAX_MUTATION_STEP);
    maxMutationsPerIndividualSpinner = new JSpinner(maxMutationsPerIndividualModel);
    JLabel maxMutationsPerIndividualLabel = new JLabel(maxMutationsPerIndividualText);
    maxMutationsPerIndividualLabel.setLabelFor(maxMutationsPerIndividualSpinner);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(maxMutationsPerIndividualLabel, constraints);
    mainPanel.add(maxMutationsPerIndividualLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(maxMutationsPerIndividualSpinner, constraints);
    mainPanel.add(maxMutationsPerIndividualSpinner);
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendCrossoverRateSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {/*from  w  ww  .j a  v a2  s .  com*/
    SpinnerModel crossoverRateModel = new SpinnerNumberModel(crossoverInitial, CROSSOVER_MIN, CROSSOVER_MAX,
            CROSSOVER_STEP);
    crossoverRateSpinner = new JSpinner(crossoverRateModel);
    JLabel crossoverRateLabel = new JLabel(crossoverRateText);
    crossoverRateLabel.setLabelFor(crossoverRateSpinner);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(crossoverRateLabel, constraints);
    mainPanel.add(crossoverRateLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(crossoverRateSpinner, constraints);
    mainPanel.add(crossoverRateSpinner);
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendMutateDuringCrossoverCheckBox(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {//w ww . j  av  a  2s. c o  m
    mutateDuringCrossoverCheckBox = new JCheckBox(mutateDuringCrossoverText);
    mutateDuringCrossoverCheckBox.setSelected(true);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    JLabel dummyJLabel = new JLabel();
    gridBagLayout.setConstraints(dummyJLabel, constraints);
    mainPanel.add(dummyJLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(mutateDuringCrossoverCheckBox, constraints);
    mainPanel.add(mutateDuringCrossoverCheckBox);
}

From source file:savant.view.dialog.LoadGenomeDialog.java

private void updateAuxiliaryList() {
    Genome curGenome = (Genome) genomesCombo.getSelectedItem();
    auxiliaryPanel.removeAll();/*from   w  w w .  ja va 2  s.c o m*/
    Auxiliary[] auxes = curGenome.getAuxiliaries();
    if (auxes.length > 0) {
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridy = GridBagConstraints.RELATIVE;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        for (Auxiliary aux : auxes) {
            JCheckBox cb = new JCheckBox(aux.toString());
            cb.setSelected(aux.type == AuxiliaryType.SEQUENCE); // Sequence track is checked by default.
            auxiliaryPanel.add(cb, gbc);
        }
    }
    pack();
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 * @return// w w w.j  ava 2  s  .  c om
 */
private JPanel createEndGradientPanel() {
    GridBagConstraints itemConstraint;
    JPanel endGradientPanel = new JPanel(new GridBagLayout());

    // add gradient end label
    JLabel gradientEndLabel = new ResourceLabel(
            "plotter.configuration_dialog.color_scheme_dialog.gradient_end");
    {
        itemConstraint = new GridBagConstraints();
        itemConstraint.weightx = 1.0;
        itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
        itemConstraint.insets = new Insets(0, 2, 0, 0);

        endGradientPanel.add(gradientEndLabel, itemConstraint);
    }

    // add gradient end color combo box
    {
        gradientEndColorComboBox = new JComboBox<Color>(gradientEndColorComboBoxModel);
        gradientEndLabel.setLabelFor(gradientEndColorComboBox);
        gradientEndColorComboBox.setPreferredSize(preferredGradientComboBoxSize);
        gradientEndColorComboBox.setRenderer(new ColorRGBComboBoxCellRenderer());
        gradientEndColorComboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                // set gradient end color to current active color scheme
                Color color = (Color) gradientEndColorComboBox.getSelectedItem();
                if (color != null && !adaptingModels) {

                    // enable apply and revert button
                    saveButton.setEnabled(true);
                    revertButton.setEnabled(true);

                    getCurrentActiveColorScheme().setGradientEndColor(ColorRGB.convertColorToColorRGB(color));
                }
                adaptGradientPlot();
                calculateGradientPreview();
            }

        });

        itemConstraint = new GridBagConstraints();
        itemConstraint.weightx = 1.0;
        itemConstraint.gridwidth = GridBagConstraints.REMAINDER; // end row
        itemConstraint.insets = new Insets(0, 2, 0, 0);

        endGradientPanel.add(gradientEndColorComboBox, itemConstraint);
    }
    return endGradientPanel;
}

From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java

/**
 * Initialize the GUI.//w w  w  .  ja va  2s .  com
 */
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
    setLayout(new GridBagLayout());

    GridBagConstraints cl = new GridBagConstraints(); // for labels
    cl.gridx = 0;
    cl.anchor = GridBagConstraints.EAST;
    cl.insets = new Insets(0, 1, 0, 1);

    GridBagConstraints ce = new GridBagConstraints(); // for editors
    ce.fill = GridBagConstraints.BOTH;
    ce.gridx = 1;
    ce.weightx = 1.0;
    ce.insets = new Insets(0, 1, 0, 1);

    GridBagConstraints cp = new GridBagConstraints(); // for panels
    cp.fill = GridBagConstraints.BOTH;
    cp.gridx = 1;
    cp.gridy = GridBagConstraints.RELATIVE;
    cp.gridwidth = 2;
    cp.weightx = 1.0;

    JPanel currentPanel = this;
    String currentGroup = DEFAULT_GROUP;
    int y = 0;

    for (int i = 0; i < editors.length; i++) {
        if (editors[i] == null) {
            continue;
        }

        if (log.isDebugEnabled()) {
            log.debug("Laying property " + descriptors[i].getName());
        }

        String g = group(descriptors[i]);
        if (!currentGroup.equals(g)) {
            if (currentPanel != this) {
                add(currentPanel, cp);
            }
            currentGroup = g;
            currentPanel = new JPanel(new GridBagLayout());
            currentPanel.setBorder(
                    BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), groupDisplayName(g)));
            cp.weighty = 0.0;
            y = 0;
        }

        Component customEditor = editors[i].getCustomEditor();

        boolean multiLineEditor = false;
        if (customEditor.getPreferredSize().height > 50 || customEditor instanceof JScrollPane
                || descriptors[i].getValue(MULTILINE) != null) {
            // TODO: the above works in the current situation, but it's
            // just a hack. How to get each editor to report whether it
            // wants to grow bigger? Whether the property label should
            // be at the left or at the top of the editor? ...?
            multiLineEditor = true;
        }

        JLabel label = createLabel(descriptors[i]);
        label.setLabelFor(customEditor);

        cl.gridy = y;
        cl.gridwidth = multiLineEditor ? 2 : 1;
        cl.anchor = multiLineEditor ? GridBagConstraints.CENTER : GridBagConstraints.EAST;
        currentPanel.add(label, cl);

        ce.gridx = multiLineEditor ? 0 : 1;
        ce.gridy = multiLineEditor ? ++y : y;
        ce.gridwidth = multiLineEditor ? 2 : 1;
        ce.weighty = multiLineEditor ? 1.0 : 0.0;

        cp.weighty += ce.weighty;

        currentPanel.add(customEditor, ce);

        y++;
    }
    if (currentPanel != this) {
        add(currentPanel, cp);
    }

    // Add a 0-sized invisible component that will take all the vertical
    // space that nobody wants:
    cp.weighty = 0.0001;
    add(Box.createHorizontalStrut(0), cp);
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendFitnessEvaluatorComboBox(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {//from ww  w. j av a2s  .  c  o m
    fitnessEvaluatorComboBox = new JComboBox<String>();
    for (FitnessEvaluatorType fitnessEvaluatorType : FitnessEvaluatorType.values()) {
        fitnessEvaluatorComboBox.addItem(fitnessEvaluatorType.name());
    }
    fitnessEvaluatorComboBox.setSelectedItem(FitnessEvaluatorType.CIPHER_SOLUTION_UNIQUE_WORD.name());
    JLabel fitnessEvaluatorNameLabel = new JLabel(fitnessEvaluatorNameText);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(fitnessEvaluatorNameLabel, constraints);
    mainPanel.add(fitnessEvaluatorNameLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(fitnessEvaluatorComboBox, constraints);
    mainPanel.add(fitnessEvaluatorComboBox);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the passed components.//from   w  ww .j a  va2  s  .c o  m
 * 
 * @param pane The main pane.
 * @param components The components to lay out.
 */
private void layoutComponents(JPanel pane, Map<JLabel, JComponent> components) {
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    Entry<JLabel, JComponent> entry;

    Iterator<Entry<JLabel, JComponent>> i = components.entrySet().iterator();
    c.gridy = 0;
    while (i.hasNext()) {
        c.gridx = 0;
        entry = i.next();
        ++c.gridy;
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE; //reset to default
        c.weightx = 0.0;
        pane.add(entry.getKey(), c);
        c.gridx++;
        pane.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;//end row
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        pane.add(entry.getValue(), c);
    }
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendCrossoverAlgorithmComboBox(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {//from w  ww.  ja  va 2  s.  co  m
    crossoverAlgorithmComboBox = new JComboBox<String>();
    for (CrossoverAlgorithmType crossoverAlgorithmType : CrossoverAlgorithmType.values()) {
        crossoverAlgorithmComboBox.addItem(crossoverAlgorithmType.name());
    }
    crossoverAlgorithmComboBox.setSelectedItem(CrossoverAlgorithmType.LOWEST_COMMON_GROUP.name());
    JLabel crossoverAlgorithmNameLabel = new JLabel(crossoverAlgorithmNameText);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(crossoverAlgorithmNameLabel, constraints);
    mainPanel.add(crossoverAlgorithmNameLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(crossoverAlgorithmComboBox, constraints);
    mainPanel.add(crossoverAlgorithmComboBox);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserProfile.java

/**
 * Builds the panel hosting the user's details.
 * //from  www  . j a  va  2s.  c  o m
 * @return See above.
 */
private JPanel buildContentPanel() {
    ExperimenterData user = (ExperimenterData) model.getRefObject();
    boolean editable = model.isUserOwner(user);
    if (!editable)
        editable = MetadataViewerAgent.isAdministrator();
    details = EditorUtil.convertExperimenter(user);
    JPanel content = new JPanel();
    content.setBorder(BorderFactory.createTitledBorder("User"));
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    Entry<String, String> entry;
    Iterator<Entry<String, String>> i = details.entrySet().iterator();
    JComponent label;
    JTextField area;
    String key, value;
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    //Add log in name but cannot edit.
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;//end row
    c.fill = GridBagConstraints.HORIZONTAL;
    content.add(buildProfileCanvas(), c);
    c.gridy++;
    c.gridx = 0;
    label = EditorUtil.getLabel(EditorUtil.DISPLAY_NAME, true);
    label.setBackground(UIUtilities.BACKGROUND_COLOR);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;//end row
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    loginArea.setText(user.getUserName());
    loginArea.setEnabled(false);
    loginArea.setEditable(false);
    if (MetadataViewerAgent.isAdministrator() && !model.isSystemUser(user.getId()) && !model.isSelf()) {
        loginArea.setEnabled(true);
        loginArea.getDocument().addDocumentListener(this);
    }
    content.add(loginArea, c);
    while (i.hasNext()) {
        ++c.gridy;
        c.gridx = 0;
        entry = i.next();
        key = entry.getKey();
        value = entry.getValue();
        label = EditorUtil.getLabel(key, EditorUtil.FIRST_NAME.equals(key) || EditorUtil.LAST_NAME.equals(key));
        area = new JTextField(value);
        area.setBackground(UIUtilities.BACKGROUND_COLOR);
        area.setEditable(editable);
        area.setEnabled(editable);
        if (editable)
            area.getDocument().addDocumentListener(this);
        items.put(key, area);
        label.setBackground(UIUtilities.BACKGROUND_COLOR);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;//reset to default
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;//end row
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        content.add(area, c);
    }
    c.gridx = 0;
    c.gridy++;
    label = EditorUtil.getLabel(EditorUtil.DEFAULT_GROUP, false);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    content.add(groupsBox, c);
    c.gridy++;
    content.add(permissionsPane, c);
    c.gridx = 0;
    c.gridy++;
    label = EditorUtil.getLabel(EditorUtil.GROUP_OWNER, false);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE; //reset to default
    c.weightx = 0.0;
    content.add(label, c);
    c.gridx++;
    content.add(Box.createHorizontalStrut(5), c);
    c.gridx++;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    c.fill = GridBagConstraints.NONE;
    c.weightx = 1.0;
    content.add(ownerBox, c);
    if (activeBox.isVisible()) {
        c.gridx = 0;
        c.gridy++;
        label = EditorUtil.getLabel(EditorUtil.ACTIVE, false);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.fill = GridBagConstraints.NONE;
        c.weightx = 1.0;
        content.add(activeBox, c);
    }
    if (adminBox.isVisible()) {
        c.gridx = 0;
        c.gridy++;
        label = EditorUtil.getLabel(EditorUtil.ADMINISTRATOR, false);
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE;
        c.weightx = 0.0;
        content.add(label, c);
        c.gridx++;
        content.add(Box.createHorizontalStrut(5), c);
        c.gridx++;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.fill = GridBagConstraints.NONE;
        c.weightx = 1.0;
        content.add(adminBox, c);
    }
    c.gridx = 0;
    c.gridy++;
    content.add(Box.createHorizontalStrut(10), c);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.MANDATORY_DESCRIPTION, Font.ITALIC);
    label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
    c.weightx = 0.0;
    content.add(label, c);
    return content;
}