[英]How to add new JTable with rows and columns by clicking button?
I am a beginner in Java and I need help. 我是Java的初学者,需要帮助。
I want to add table with rows and columns in JFrame
or JPanel
when a button is clicked. 我想在单击按钮时在
JFrame
或JPanel
添加具有行和列的表。 How to add new table with rows and columns by clicking button? 如何通过单击按钮添加具有行和列的新表?
JButton
to frame JButton
添加到框架 ActionListener
in button ActionListener
than make a list when button is pressed like this 像这样按下按钮时列出清单
JButton b = new JButton("Click Me"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; Object[][] data = { {"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)}, {"John", "Doe", "Rowing", new Integer(3), new Boolean(true)}, {"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)}, {"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)}, {"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)} }; JTable table = new JTable(data, columnNames); add(table); } });
More information on JButton
& JTable
. 有关
JButton
和JTable
更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.