使用 Swing UI 设计器在 JTabbedPane 中创建 JTable - Intellij

问题描述

我正在尝试创建一个带有多个选项卡的框架,每个选项卡都有一个不同的列表。我使用带有 Intellij 的 Swing UI 设计器来创建“资产”,然后在我的主类文件中修改它们。我已经查找了一些使用设计器创建 JTable 的示例,但这些示例不使用多个选项卡,我认为这是我现在的主要问题,因为我无法弄清楚如何去做。>

这是现在的代码。

package client;

import javax.swing.*;
import javax.swing.table.TableModel;
import java.awt.event.*;

public class ATCGUI extends GUI {

    private JPanel mainPanel;
    private JTabbedPane tabbedPanel;
    private JPanel tabbedAirportInfo;

    private JScrollPane scrollPane;
    private JButton addButtonOut;
    private JButton deleteButtonOut;
    private JButton addButtonIn;
    private JButton deleteButtonIn;
    private JTable tableOut;
    private JTable tableIn;
    private JPanel panelOut;
private JScrollPane tabbedPaneOut;

    public ATCGUI(String AirportCode) {

        this.add(mainPanel);

        String airportID = getID(AirportCode);

        TableOut(airportID);

        pack();
        setVisible(true);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    private void TableOut(String airportID){
        String[] columnNames = {"Airline","Destination","Aircraft"};

        Object[][] dataTest = {{"Iberia","London","737"},{"AirEuropa","Paris","320"},{"BritishAirways","Berlin","330"}};

        JTable TableOut = new JTable(dataTest,columnNames);

        setContentPane(panelOut);
    }
    public static void main(String[] args) {
        new ATCGUI("MAD");
    }
}

现在它显示了不同的选项卡,但 JTable 没有出现在任何选项卡中。我确实确保将 JTable 放在 JScrollPane 中。

我对此很陌生,所以也许我错过了一些东西,或者只是不知道。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)