java如何更改窗口的颜色
我正在用java制作一个网络应用程序,这是一个连接多个终端的服务器。我想给服务器应用一种更暗的感觉(灰色和黑色),但是我似乎无法改变默认浅灰色的背景色
下面是我的应用程序的图片,这样你就可以知道我在做什么:
我试着用
this.getContentPane().setBackground(new Color(50, 50, 50));
然而,这并没有改变背景颜色。我还尝试过改变JScrollPane的背景色和前景色,但没有任何效果
更改表格的背景只会使单元格的背景变暗,而不会使窗口的其余部分变暗。感谢您的帮助
谢谢
编辑: 以下是我目前的代码:
JTable serverList;
JScrollPane scrollPane;
Container container = this.getContentPane();
public GuiMain()
{
this.setLayout(new BorderLayout());
this.getContentPane().setBackground(new Color(50, 50, 50));
serverList = new JTable(Variables.servers, Variables.serversHeader);
serverList.setRowSelectionAllowed(true);
scrollPane = new JScrollPane(serverList);
serverList.setFillsViewportHeight(true);
add(scrollPane, BorderLayout.NORTH);
}
# 1 楼答案
ScrollPane占据了整个窗口,因此您试图消除的浅灰色背景来自ScrollPane的视口。以下是如何改变它: