0

I am making a networking app in java, which is a server that connects several terminals together. I wanted to give the server app a darker feel (grays and blacks), however I cannot seem to change the background color from its default light gray.

Here's a picture of my application so you can tell what I'm doing:

picture of program

I tried using

this.getContentPane().setBackground(new Color(50, 50, 50));

however that didn't change the background color. I also tried changing the JScrollPane's background and foreground color, but that didn't do anything.

Changing the table's background only makes the background of the cells darker, not the rest of the window. Any help is appreciated!

Thanks

EDIT: Here is my code so far:

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 に答える