私はGUIベースのプロジェクトに取り組んでおり、jpanelにjtableを追加する必要があります。しかし、スクロールペインで追加するとテーブルが表示されない理由がわかりません。助けてくれてありがとう...以下は私が使用しているコードです..
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class FrmAddEditDN extends JDialog{
JButton JBUpdate = new JButton(new ImageIcon("images/save.png"));
JButton JBReset = new JButton("Reset",new ImageIcon("images/reset.png"));
JButton JBCancel = new JButton("Cancel",new ImageIcon("images/cancel.png"));
JLabel JLPic1 = new JLabel();
JLabel JLBanner = new JLabel("Please fill-up all the required fields.");
public FrmAddEditDN(boolean ADD_STATE,JFrame OwnerForm,Connection srcCN,String srcSQL){
super(OwnerForm,true);
cnAEDN = srcCN;
ADDING_STATE = ADD_STATE;
JPanel JPContainer = new JPanel();
JPContainer.setLayout(null);
String[] columnNames = {
"Sr No","Invoice No","Invoice Date","Consignee","Description","Basic Amount","Invoice Amount","Payment Received",
"EFT Date","Payment Earlier Received","Comm. @ %","Comm.Claim @ %","Comm. Received","Date","Bank","Remarks"};
String[][] data = {
{"","","","","","","","","","","","","","","",""}
};
DefaultTableModel DTModel = new DefaultTableModel(data,columnNames);
JTable table = new JTable(5,16);
table.setBounds(15,295,screen.width-40,150);
table.setRowHeight(30);
table.setForeground(Color.black);
table.setBackground(Color.white);
JTableHeader header = table.getTableHeader();
header.setForeground(Color.red);
header.setBackground(Color.green);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(0).setPreferredWidth(2);
table.getColumnModel().getColumn(1).setPreferredWidth(50);
JScrollPane tableContainer = new JScrollPane();
tableContainer.setViewportView(table);
JPContainer.add(tableContainer);
getContentPane().add(JPContainer);
setSize(screen.width-5,screen.height-45);
setResizable(false);
setLocation(0,0);
}
}