JTableをJFrameに表示することができません。実際には、ArrayListからデータを抽出し、JTable行を行ごとに埋めました。 JTableが塗りつぶされていることを確認しました。行数は元のArrayListの行数と同じです。ただし、この関数を実行すると空白のGUIが表示されます。JTableがJframeに表示されない
public Graphicalinterface4() {
//super (new GridLayout(1,0));
//panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
getdata2 in=new getdata2();
try {
ArrayList<Piece> test=in.getList();
ArrayList<Piece> classified=in.classify(test);
JTable table=getlocaltable(classified);
table.setFillsViewportHeight(true);
JScrollPane scrPane=new JScrollPane(table);
//scrPane.setSize(800,690);
//scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.add(scrPane);
//scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
}
catch (IOException ex) {
ex.printStackTrace();
}
}
public JTable getlocaltable(ArrayList<Piece> in) {
//new Object[]{"Type","Company","reference","description","price","To order"}));
//DefaultListModel<Piece> testlst=new DefaultListModel<Piece>();
int sz=in.size();
String[] columns=new String[] {
"Type","Company","reference","description","price","To order"
};
DefaultTableModel model = new DefaultTableModel();
//JTable table=new JTable(null, in.toArray());
for (int i=0;i<sz;i++) {
Piece p=in.get(i);
String type=p.gettype();
String company=p.getasc();
String reference=p.getref();
String description=p.getdesc();
String price=p.getprice();
String image=p.getimage();
System.out.println(type);
//DefaultTableModel model=(DefaultTableModel) table.getModel();
model.addRow(new Object[]{type,company,reference,description,price,Integer.toString(0)});
}
JTable table=new JTable(model);
System.out.println(table.getRowCount());
return table;
}
static Graphicalinterface4 ssp;
public static void main(String[] args) throws IOException {
SwingUtilities.invokeLater(new Runnable() {
public void run() {ssp=new Graphicalinterface4();}
});
}
1)が反転されているオブジェクトの一般的なJavaの命名法を習得してください(名前付け規則 - 例えば 'EachWordUpperCaseClass'、' firstWordLowerCaseMethod() '、' firstWordLowerCaseAttribute'が 'UPPER_CASE_CONSTANT'でなければ)それを一貫して使用してください。 2)すぐに助けを得るために、[MCVE]または[短く、自己完結型の正しい例](http://www.sscce.org/)を投稿してください。 –