本文整理汇总了Java中javax.swing.JButton.add方法的典型用法代码示例。如果您正苦于以下问题:Java JButton.add方法的具体用法?Java JButton.add怎么用?Java JButton.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JButton
的用法示例。
在下文中一共展示了JButton.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContributeButton
import javax.swing.JButton; //导入方法依赖的package包/类
public JButton getContributeButton() {
JButton contributeB = new JButton();
contributeB.setLayout(new BorderLayout());
JLabel label1 = new JLabel("Contribute");
JLabel label2 = new JLabel("Data");
label1.setFont(new Font("Arial", Font.BOLD, 11));
contributeB.add(BorderLayout.CENTER,label1);
label2.setFont(new Font("Arial", Font.BOLD, 11));
label2.setHorizontalAlignment(SwingConstants.CENTER);
contributeB.add(BorderLayout.SOUTH,label2);
contributeB.setSize(new Dimension(115, 30));
contributeB.setMargin(new Insets(0, 0, 0, 0));
contributeB.setBackground(new Color( 224, 224, 224)); ;
contributeB.setFont(new Font("Arial", Font.BOLD, 11));
contributeB.setHorizontalAlignment(SwingConstants.LEFT);
return contributeB;
}
示例2: update
import javax.swing.JButton; //导入方法依赖的package包/类
/**
* Updates this panel's labels so that the information it displays
* is up to date.
*/
public final void update() {
removeAll();
final Player player = getMyPlayer();
final Europe europe = player.getEurope();
add(question, "span, wrap 20");
// The prices may have changed, recreate the buttons
buttons.clear();
for (UnitType ut : sort(units, priceComparator)) {
int price = europe.getUnitPrice(ut);
boolean enable = player.checkGold(price);
JButton newButton = new JButton();
newButton.setLayout(new MigLayout("wrap 2", "[60]", "[30][30]"));
ImageIcon icon = new ImageIcon(getImageLibrary().getSmallUnitImage(
ut, !enable));
JLabel name = Utility.localizedLabel(ut);
name.setEnabled(enable);
JLabel gold = Utility.localizedLabel(StringTemplate
.template("goldAmount")
.addAmount("%amount%", price));
gold.setEnabled(enable);
newButton.setEnabled(enable);
newButton.add(new JLabel(icon), "span 1 2");
newButton.add(name);
newButton.add(gold);
newButton.setActionCommand(ut.getId());
newButton.addActionListener(this);
buttons.add(newButton);
add(newButton, "grow");
}
add(okButton, "newline 20, span, tag ok");
setSize(getPreferredSize());
revalidate();
shouldEnable = player.checkGold(europe.getUnitPrice(first(units)));
}