我正在攀登Java学习曲线,第一次需要一个JTable。我想要的是显示一个空表,所有单元格都是空的,除了列标题。然后,根据用户操作,表格被填充了字符串、整数和浮点数的混合物。
我在网上找到的所有示例都创建在实例化时就被填充的表。有没有简单的方法可以推迟填充表,但在启动时显示它?
提前感谢任何帮助。
我正在攀登Java学习曲线,第一次需要一个JTable。我想要的是显示一个空表,所有单元格都是空的,除了列标题。然后,根据用户操作,表格被填充了字符串、整数和浮点数的混合物。
我在网上找到的所有示例都创建在实例化时就被填充的表。有没有简单的方法可以推迟填充表,但在启动时显示它?
提前感谢任何帮助。
创建一个具有指定行数和列数的表模型,并将其用于您的JTable中。例如:
String[] colHeadings = {"COLUMN1","COLUMN2"};
int numRows = 5 ;
DefaultTableModel model = new DefaultTableModel(numRows, colHeadings.length) ;
model.setColumnIdentifiers(colHeadings);
JTable table = new JTable(model);
然后您可以在模型上调用方法以更新值、添加行等。
我希望这是你所期待的......。
这是我为一个旧项目所做的事情。我将所有单元格设置为null,因为我只想要一个4行4列的表格,所以在声明语句中初始化它们很容易。
jTable1.setModel(new DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
}, new String [] {"Title 1", "Title 2", "Title 3", "Title 4"}
));
然后要更新行和/或列,请使用以下方法...
jTable1.setValueAt(Object data, int row, int column);
或者对于多行或多列,使用循环。祝你好运。
I want write custom TreeCellRenderer to have Root, nodes and leafs in different color. This is my code: tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component ...
Anyone written a JLabel (extension/util/??) that automatically abbreviates the contents depending on it s preferred/visible size? much appreciated.
i tried this link: http://downloads.myeclipseide.com/downloads/products/eworkbench/discovery-6.0/ but i m fail how is this?
I would like to add a hint value to my javax.swing.JTextField. It should look like Firefox rendering of <input type="text" title="bla">. This creates an edit field with the text bla in the ...
I need to develop some java gui using swing. A few years ago I did develop a bit with swing. But it was pretty exhausting, you see, back than there weren t much tools to help you. But I do believe ...
I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...
Consider the Java code below, what would happen if there were no paintComponent method in JPanel class? ... import javax.swing.JPanel; public class ShapesJPanel extends JPanel { public void ...
My current code looks like this: final String[] value = new String[1]; SwingUtilities.invokeAndWait(new Runnable() { public void run() { value[0] = textArea.getText(); } }); The use ...