0

我正在用 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);
    }
4

1 回答 1

1

ScrollPane 占据了整个窗口,因此您试图摆脱的浅灰色背景来自 ScrollPane 的视口。以下是如何更改它:

scrollPane.getViewport().setBackground(new Color(50, 50, 50));
serverList.setFillsViewportHeight(false);
// ^-- so that the JTable does not fill the Viewport
于 2013-05-19T16:19:36.260 回答