下面列出了怎么用javax.swing.plaf.metal.MetalButtonUI的API类实例代码及写法,或者点击链接到github查看源代码。
private static JButton createColorButton(Color color) {
JButton colorButton = new JButton();
colorButton.setPreferredSize(new Dimension(30, 20));
colorButton.setBorder(BorderFactory.createLineBorder(Color.darkGray));
colorButton.setBackground(color);
colorButton.setForeground(color);
colorButton.setUI(new MetalButtonUI());
//colorButton.setActionCommand("" + i);
colorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//int i = Integer.parseInt(e.getActionCommand());
Color newColor = JColorChooser.showDialog(Gui.frame, "Choose Color", ((JButton) e.getSource()).getBackground());
if (newColor != null) {
((JButton) e.getSource()).setBackground(newColor);
((JButton) e.getSource()).setForeground(newColor);
}
}
});
return colorButton;
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}
private void setUI() {
// This fixes an issue where the WindowsButtonUI wants to draw a border
// around a button that isn't in a toolbar. This occurs even if you set
// an empty border because it ignores your border and draws its own.
setUI(MetalButtonUI.createUI(this));
}