清空表格内容代码如下:
DefaultTableModel model =(DefaultTableModel) jTable1.getModel()
while(model.getRowCount()>0){
model.removeRow(model.getRowCount()-1)
}
Swing是一个用于开发Java应用程序用户界面的开发工具包。以抽象窗口工具包(AWT)为基础使跨平台应用程序可以使用任何可插拔的外观风格。
package com.networkimport java.awt.BorderLayout
import java.awt.Color
import java.util.Vector
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.JScrollPane
import javax.swing.JTabbedPane
import javax.swing.JTable
import javax.swing.table.DefaultTableModel
public class TableWin extends JFrame{
private Vector data1
private Vector data2
public TableWin(Vector data1,Vector data2) {
this.data1 = data1
this.data2 = data2
addItems()
setWin()
}
private void setWin() {
this.setSize(400, 550)
this.setLocationRelativeTo(null)
this.getContentPane().setBackground(new Color(249,208,241))
}
private void addItems() {
JTabbedPane tp = new JTabbedPane()
JPanel p1 = house()
tp.add("房间详情",p1)
this.add(tp)
}
private JPanel house() {
JPanel p = new JPanel(new BorderLayout())
Vector<String >titel= new Vector<String>()
titel.add("房号")
titel.add("房间类型")
titel.add("状态")
titel.add("入住旅客")
JTable table = new JTable(data1,titel)
JScrollPane sp = new JScrollPane(table)
p.add(sp,new BorderLayout().CENTER)
return p
}
}
package com.start
import java.util.Vector
import com.network.TableWin
import com.network.Win
public class Start {
public static void main(String[] args) {
Vector<Vector>v1 = new Vector<Vector>()
Vector<String>v = new Vector<String>()
for(int i=0i<5i++){
v.add("o"+i)
}
v1.add(v)
Vector<String>v2 = new Vector<String>()
Vector<String>vv = new Vector<String>()
for(int i=0i<5i++){
vv.add("oo"+i)
}
v1.add(vv)
new TableWin(v1,v2).setVisible(true)
}
}