下面列出了javax.swing.JButton#setAlignmentY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Return a button suitable for linking to another panel
* (e.g. ColopediaPanel).
*
* @param text a {@code String} value
* @param icon an {@code Icon} value
* @param action a {@code String} value
* @return a {@code JButton} value
*/
public static JButton getLinkButton(String text, Icon icon, String action) {
JButton button = new JButton(text, icon);
button.setMargin(EMPTY_MARGIN);
button.setOpaque(false);
button.setForeground(LINK_COLOR);
button.setAlignmentY(0.8f);
button.setBorder(blankBorder(0, 0, 0, 0));
button.setActionCommand(action);
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
return button;
}
protected void initLayout() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
objectiveModel = new ObjectiveTableModel();
final JTable table = new JTable(objectiveModel);
table.getTableHeader().setReorderingAllowed(false);
final TableColumn column0 = table.getColumnModel().getColumn(0);
column0.setPreferredWidth(34);
column0.setWidth(34);
column0.setMaxWidth(34);
column0.setCellRenderer(new ColorTableCellRenderer());
final TableColumn column1 = table.getColumnModel().getColumn(1);
column1.setCellEditor(new EditorPaneCellEditor());
column1.setCellRenderer(new EditorPaneTableCellRenderer());
final JScrollPane scroll = new JScrollPane(table);
final JButton refresh = new JButton("Refresh Objectives");
refresh.setAlignmentY(Component.CENTER_ALIGNMENT);
refresh.addActionListener(
SwingAction.of(
"Refresh Objectives",
e -> {
objectiveModel.loadData();
SwingUtilities.invokeLater(table::repaint);
}));
add(Box.createVerticalStrut(6));
add(refresh);
add(Box.createVerticalStrut(6));
add(scroll);
}
/**
* Get Default OK Button from LookAndFeel (like JOptionPane)
*/
public static JButton newOKButton() {
String text = StaticMessageSource.getMessage("Accept");
int mnemonic = getMnemonic("OptionPane.okButtonMnemonic");
JButton b = new JButton(text, OK_ICON);
b.setMnemonic(mnemonic);
b.setAlignmentX(Container.CENTER_ALIGNMENT);
b.setAlignmentY(Container.CENTER_ALIGNMENT);
return b;
}
/**
* Get Default Cancel Button from LookAndFeel (like JOptionPane)
*/
public static JButton newCancelButton() {
String text = StaticMessageSource.getMessage("Cancel");
int mnemonic = getMnemonic("OptionPane.cancelButtonMnemonic");
JButton b = new JButton(text, CANCEL_ICON);
b.setMnemonic(mnemonic);
b.setAlignmentX(Container.CENTER_ALIGNMENT);
b.setAlignmentY(Container.CENTER_ALIGNMENT);
return b;
}