为你的界面上色等
关键词:awt; swing; java gui;
1。设置普通按钮等的颜色
假设有一个界面类
public class xxxx{
...
private JButton connectButton;
private JPanel jPanelNorth1;
...
}
构造方法
public xxxx() {
...
connectButton = new JButton("connect");
jPanelNorth1 = new JPanel();
...
//为connectButton上色
jPanelNorth1.add(connectButton);
connectButton.setBackground(new Color(30, 30, 30));//背景颜色
connectButton.setForeground(new Color(32, 178, 170));//文字颜色
connectButton.setBorder(BorderFactory.createLineBorder(new Color(34, 139, 34)));//设置面板边框颜色
}
2.1。 设置弹出窗口的ui
//弹窗ui
UIManager UI=new UIManager();
UI.put("OptionPane.background", new Color(30, 30, 30));
UI.put("Panel.background", new Color(30, 30, 30));
UI.put("Button.background", new Color(30, 30, 30));
2.2。 设置弹出窗口的文字和按键自定义
public class xxxx{
...
public Object[] red_options = {"<html><font color="+"RED"+">OK</font></html>"};
...
}
...
...
// 单击连接按钮时事件
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int port;
if (isConnected) {
JOptionPane.showOptionDialog(clientFrame,"<html><font color="+"red"+" size="+"6"+">already connected!</font></html>","error",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, red_options, red_options[0]);
return;
}
...
...
3 。窗口标题
clientFrame = new JFrame("client terminal");
visitor tracker