Create a JTable inside a JTabbedPane using Swing UI designer
Answered
I'm trying to create a frame with multiple tabs, each with a different list. I've used the Swing UI designer with Intellij to create the "assets" and then modified them in my main class file. I've looked up some examples of creating a JTable using the designer, but these don't use multiple tabs, which I think is the main problem for me right now as I am not able to figure out how to do it.
This is the code for now.
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;
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);
}
}
For now it shows the different tabs, but the JTable doesn't appear in any of the tabs. And I did make sure to put the JTable inside a JScrollPane.
I'm pretty new to this so maybe there's something I've missed out or just simply don't know.
Please sign in to leave a comment.
Please track this question on StackOverflow: https://stackoverflow.com/questions/67257377/create-a-jtable-inside-a-jtabbedpane-using-swing-ui-designer-intellij
IDEs support forum is intended to be used as a portal where one could get help for IDE-related issues. This one is more about swing functionality and hardly related to the IDE itself.
I've seen a couple posts regarding Swing UI on this forum so I thought I'd give it a try. But okay, that's understandable, sorry