Hi!
I would like to create textfields that will serve for sorting data in JTable, and the width of these textfields will correspond to a column width. So, below you may see the code that worked until I did not use an array of textfields. Now, the size of txtRegNum
and txtRegDate
corresponds to the conlumn width, however all remaining textfields created from an array are very short. Why does it happen? Should I use any other method for an array of textfields?
Thanks!
sorter = new TableRowSorter<QueryTableModel>(SystClasses.Form.tableModel);
table.setRowSorter(sorter);
table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
public void columnMarginChanged(ChangeEvent e) {
txtRegNum.setPreferredSize(new Dimension(table.getColumn("reg_num").getPreferredWidth(),txtRegNum.getPreferredSize().height));
txtRegDate.setPreferredSize(new Dimension(table.getColumn("reg_date").getPreferredWidth(),txtRegDate.getPreferredSize().height));
for (int i=0; i < NrOfTextFields; i++) {
txtAttrTextFields[i].setPreferredSize(new Dimension(table.getColumn(attrTitle.elementAt(i).toString()).getPreferredWidth(),txtAttrTextFields[i].getPreferredSize().height));
}
txtAttachedFile.setPreferredSize(new Dimension(table.getColumn("attached_file").getPreferredWidth(),txtAttachedFile.getPreferredSize().height));
}
public void columnAdded(TableColumnModelEvent e) {}
public void columnRemoved(TableColumnModelEvent e) {}
public void columnMoved(TableColumnModelEvent e) {}
public void columnSelectionChanged(ListSelectionEvent e) {}
});