I'm very new to all things Java. I'm just trying to create a simple application with multiple forms. I have created a Swing form that will be the basis for all other forms. I am then trying to instantiate the generic Swing form and add components particular to whichever form I am then creating.
I am having particular trouble adding a JTable on one of the forms to a layout.
Here is my minimal code example:
The template form:
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class FormLayout extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
public FormLayout() throws SQLException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 850, 800);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup())
);
contentPane.setLayout(gl_contentPane);
//gl_contentPane.add(new JScrollPane(table), BorderLayout.CENTER);
}
}
The calling class:
import java.awt.EventQueue;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JTable;
public class Main extends FormLayout {
private static final long serialVersionUID = 1L;
public Main() throws SQLException{
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FormLayout frame = new FormLayout();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void MainForm() throws SQLException{
String str = "select * from tblEndoscopy";
ResultSet rs = Bquery.resultQuery(str);
JTable table = new JTable(Bquery.buildTableModel(rs));
// HOW DO I ADD THIS JTABLE TO THE TEMPLATE
// FORM i.e. TO THE GROUPED PANEL?
}
}