我正在使用NET Beans IDE在LINUX中开发我的应用程序.我使用synthetica包来产生新的外观和感觉.一直都很好.
现在我的下一个阶段是在某些数据库状态发生变化时为按钮添加颜色.
例如:
在一家餐馆,我有2张桌子,当有8个人进来用餐时,我将在我的软件中创建2个桌子,因为人们无人看管我希望这两个桌子的按钮是绿色的.处理任何这些表的订单时,处理表的按钮颜色应更改为橙色.处理时,它应该是闪烁的颜色.如何在java中执行此操作?我将负责数据库更新我只想知道如何更改按钮的颜色和添加闪烁技术.
我有一个JButton,我想将背景设置为一种颜色。
JButton button = new JButton();
button.setVisible(true);
button.setPreferredSize(new Dimension(student_scroll.getWidth(), 50));
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
button.setBackground(Color.BLACK);
button.setForeground(Color.WHITE);
button.setOpaque(true);
Run Code Online (Sandbox Code Playgroud)
我在Mac上使用了它,并且按我的意愿出现了。但是,在Windows上尝试时,前景为白色(应有),但背景为空。
说添加button.setContentAreaFilled(false);我做了但没有效果的。大多数其他人说添加button.setOpaque(true);我也已经做过的。
我还必须做些什么才能使它显示为黑色背景?
编辑
根据要求,SSCCE:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class MainSwing extends JFrame {
private static final long serialVersionUID = -8231889836024827530L;
public static void main(String[] args) {
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
UIManager.put("ScrollBarUI", "main.CustomScrollBarUI");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException: " + e.getMessage());
} …Run Code Online (Sandbox Code Playgroud)