相關(guān)資訊
- 《戰(zhàn)國(guó)無(wú)雙4-2》怎么換服裝?戰(zhàn)國(guó)無(wú)
- 關(guān)于責(zé)任的名言警句大全
- 《戰(zhàn)國(guó)無(wú)雙4-2》PC版如何聯(lián)機(jī)? 戰(zhàn)
- 戰(zhàn)國(guó)無(wú)雙4-2技能覺醒牛逼嗎 全新
- 《戰(zhàn)國(guó)無(wú)雙4-2》手柄無(wú)效怎么解決
- 戰(zhàn)國(guó)無(wú)雙4-2如何設(shè)置語(yǔ)言 戰(zhàn)國(guó)無(wú)雙
- 戰(zhàn)國(guó)無(wú)雙4-2怎么樣跳過進(jìn)入開場(chǎng)動(dòng)畫
- 什么是應(yīng)屆生畢業(yè)生
- 應(yīng)屆生簡(jiǎn)歷自我評(píng)價(jià)
- 應(yīng)屆生簡(jiǎn)歷怎么寫
本類常用軟件
-
福建農(nóng)村信用社手機(jī)銀行客戶端下載下載量:584204
-
Windows優(yōu)化大師下載量:416898
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農(nóng)村信用社手機(jī)銀行客戶端下載下載量:365699
-
快播手機(jī)版下載量:325855
下面的例子將JTable做為一個(gè)輸入數(shù)據(jù)的文本框,當(dāng)雙擊擊每行第一個(gè)格子時(shí),自動(dòng)添加一個(gè)空白行
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class NewJFrame extends javax.swing.JFrame {
private JScrollPane scrollPane;
private JTable table;
private Vector<String> currentRow;
private Vector<String> currentRow1;
private Vector<Vector<String>> rows;
private Vector<String> colHeader;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public NewJFrame() {
scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
scrollPane.setPreferredSize(new java.awt.Dimension(392, 109));
String colName[] = {"c1","c2","c4","c5"};
colHeader = new Vector<String>();
rows = new Vector<Vector<String>>();
currentRow = new Vector<String>();
for(int i = 0;i< 4;i++){
colHeader.add(colName[i]);
currentRow.add("");
}
rows.addElement(currentRow);
TableModel tableModel = new DefaultTableModel(rows, colHeader);
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {
if(table.getSelectedColumn() == 0)
addRow();
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
});
scrollPane.setViewportView(table);
setSize(400, 300);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
public void addRow(){
currentRow1 = new Vector<String> ();
for(int i = 0;i< 4;i++){
currentRow1.add("");
}
rows.addElement(currentRow1);
}
}
效果圖