我有这个代码:
JPanel textPanel = new JPanel();
textPanel.setLayout(new GridLayout(0,1));
//JPanel text = new JPanel();
//text.setBorder(new TitledBorder(new EtchedBorder(), "Disploay Area"));
MyModel model = new MyModel();
//sorter = new TableRowSorter<MyModel>(model);
final JTable table = new JTable(model);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
table.setAutoCreateRowSorter(true);
//table.setRowSorter(sorter);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
int viewRow = table.getSelectedRow();
if (viewRow < 0) {
//Selection got filtered away.
txtstatus.setText("");
} else {
int modelRow =
table.convertRowIndexToModel(viewRow);
txtstatus.setText(
String.format("Selected Row in view: %d. " +
"Selected Row in model: %d.",
viewRow, modelRow));
}
}
}
);
JScrollPane scroll = new JScrollPane(table);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
textPanel.add(scroll, BorderLayout.CENTER);
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.ipadx = 800;
c.gridy = 1;
c.ipady = 460;
c.anchor = GridBagConstraints.CENTER;
c.gridwidth = 1;
c.gridheight = 1;
c.insets = new Insets(0,0,0,0);
con.add(textPanel, c);
我真的对我所做的事情感到困惑,因为我设计的程序可以正常工作,但是如果我想调整一行,那么我可以看到所有信息会挤压其余的列。无论如何,如果我想调整不会影响其余列的列的大小?
我GUI
已经连接到数据库并检索信息并显示在JTable
. 任何帮助将非常感激。