下面列出了java.awt.GridBagConstraints#BASELINE_LEADING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
/**
* 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));
}
@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();
}
}