Java,Girdlayout,Scrollpane不起作用



我有两个jtable,每个jtable都添加到带有边框的容器中(boderlayout.page_start tobledheader和中心的JTable(。这些容器都添加到jscrollpane中。

将两个容器添加到带有Gridlayout的容器中,该容器被添加到Jpanel的中心。

问题是,滚动条没有显示出来,或者是否会一直显示滚动条,它一直无法正常工作。JTable有100多个条目,但仅显示了第一个〜30个条目。

我已经尝试搜索并找到了一些可能的修复程序,但是它们没有起作用。我已经尝试了最喜欢的尺寸,在滚动板上添加了一个布局和其他一些可能性,但没有任何效果。

JTable的一些代码:

        this.locations = new JTable(data, columnNames);
        this.locations.getTableHeader().setReorderingAllowed(false);
        this.locations.setDefaultEditor(Object.class, null);
//      this.locations.setPreferredSize(new Dimension(100, 100));
        Container table = new Container();
        table.setLayout(new BorderLayout());
        table.add(this.locations.getTableHeader(), BorderLayout.PAGE_START);
        table.add(this.locations, BorderLayout.CENTER);
        JScrollPane scrollPane = new JScrollPane(table);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        this.content.add(scrollPane);

位置是JTable,内容是带有Gridlayout的容器,然后将其添加到JPANEL中。

    Container table = new Container();
    table.setLayout(new BorderLayout());
    table.add(this.locations.getTableHeader(), BorderLayout.PAGE_START);
    table.add(this.locations, BorderLayout.CENTER);

不需要上述代码。

您只需要:

    this.locations = new JTable(data, columnNames);
    JScrollPane scrollPane = new JScrollPane(table);
    this.content.add(scrollPane);

最新更新