Java Code Examples for java.awt.GridBagConstraints#BASELINE_LEADING

The following examples show how to use java.awt.GridBagConstraints#BASELINE_LEADING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleIntegerFieldOptionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SingleIntegerFieldOptionsPanel(String labelString,
                                      final InspectionProfileEntry owner,
                                      @NonNls final String property,
                                      int integerFieldColumns) {
    super(new GridBagLayout());
    final JLabel label = new JLabel(labelString);
    final JFormattedTextField valueField = createIntegerFieldTrackingValue(owner, property, integerFieldColumns);
    final GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.insets.right = UIUtil.DEFAULT_HGAP;
    constraints.weightx = 0.0;
    constraints.anchor = GridBagConstraints.BASELINE_LEADING;
    constraints.fill = GridBagConstraints.NONE;
    add(label, constraints);
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.insets.right = 0;
    constraints.anchor = GridBagConstraints.BASELINE_LEADING;
    constraints.fill = GridBagConstraints.NONE;
    add(valueField, constraints);
}
 
Example 2
Source File: Inspector.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Appends a new row containing 3 objects to this inspector.
 * 
 * The identifier is right-aligned. The leftControl is right-aligned, and
 * the rightControl is right-aligned against the far right margin of the
 * inspector.
 * 
 * @param identifier
 *            the control on the left. This should usually contain text. A
 *            <code>JLabel</code> or a <code>JCheckBox</code> is
 *            recommended.
 * @param leftControl
 *            any other control.
 * @param stretchToFill
 *            whether the <code>leftControl</code> should stretch to fit the
 *            remaining width.
 * @param rightControl
 *            the element to add on the right.
 */
public InspectorRowPanel addRow(JComponent identifier,
		JComponent leftControl, boolean stretchToFill,
		JComponent rightControl) {
	prepare(Position.LEAD, identifier);
	Position pos = stretchToFill ? Position.MAIN_WITH_LEAD_STRETCH_TO_FILL
			: Position.MAIN_WITH_LEAD_NO_STRETCH;
	prepare(pos, leftControl);
	prepare(Position.TRAIL, rightControl);

	JPanel controlPanel = new JPanel(new GridBagLayout());
	controlPanel.setOpaque(false);
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 1;
	c.weighty = 1;
	c.anchor = GridBagConstraints.BASELINE_LEADING;
	c.fill = stretchToFill ? GridBagConstraints.BOTH
			: GridBagConstraints.NONE;
	c.insets = getInsets(pos, leftControl);
	controlPanel.add(leftControl, c);
	c.gridx++;
	c.weightx = 0;
	c.fill = GridBagConstraints.NONE;
	c.anchor = GridBagConstraints.BASELINE_TRAILING;
	c.insets = getInsets(Position.TRAIL, rightControl);
	controlPanel.add(rightControl, c);
	controlPanel.putClientProperty(PROPERTY_WRAPPED, Boolean.TRUE);
	return addRow(new InspectorRow(identifier, controlPanel, false, 0));
}
 
Example 3
Source File: DataViewUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JButton button = (JButton) e.getSource();
    JCheckBox firstEntry = null;
    JPopupMenu popupMenu = new JPopupMenu();

    JPanel menuPanel = new JPanel();
    menuPanel.setFocusCycleRoot(true);
    popupMenu.add(menuPanel);
    menuPanel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.BASELINE_LEADING;
    constraints.weightx = 1;
    constraints.gridx = 0;
    
    Set<Integer> visibleColumns = dataPanel.getVisibleColumns();
    DataViewTableUIModel dvtm = dataPanel.getModel();
    
    for(int i = 0; i < dvtm.getColumnCount(); i++) {
        JCheckBox columnEntry = new JCheckBox(dvtm.getColumnName(i));
        columnEntry.setActionCommand(Integer.toString(i));
        columnEntry.setSelected(visibleColumns.contains(i));
        columnEntry.addActionListener(columnVisibilityToggler);
        constraints.gridy += 1;
        menuPanel.add(columnEntry, constraints);
        if(firstEntry == null) {
            firstEntry = columnEntry;
        }
    }
    
    constraints.gridy += 1;
    menuPanel.add(new JSeparator(), constraints);
    
    JCheckBox checkboxItem = new JCheckBox("Fit column width");
    checkboxItem.setSelected(dataPanel.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF);
    checkboxItem.addActionListener(fitColumnWidthToggler);
    
    constraints.gridy += 1;
    menuPanel.add(checkboxItem, constraints);
    
    popupMenu.show(button, 0, button.getHeight());
    if(firstEntry == null) {
        checkboxItem.requestFocus();
    } else {
        firstEntry.requestFocus();
    }
}