?? studinfotablepanel.java
字號:
package Panel.StudentInfo;
import java.util.*;
import javax.swing.*;
import Sys.vo.*;
import Sys.dao.*;
public class StudInfoTablePanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L;
public StudInfoTablePanel() {
initComponents();
}
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
studentinfotable=new StudentInfoTable();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jButton1 = new javax.swing.JButton();
setLayout(new java.awt.GridBagLayout());
jLabel1.setFont(new java.awt.Font("宋體", 1, 24));
jLabel1.setText("\u5b66\u751f\u4fe1\u606f\u8868");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jLabel1, gridBagConstraints);
jTextField1.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jTextField1, gridBagConstraints);
jLabel2.setFont(new java.awt.Font("宋體", 0, 14));
jLabel2.setText("\u7d22\u5f15\u5b66\u53f7");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jLabel2, gridBagConstraints);
//設置面板內容
studentinfotable.setRowHeight(studentinfotable.getRowHeight()+6);
jScrollPane1.setViewportView(studentinfotable);
StudentInfoDao studentinfodao=new StudentInfoDao();
List<StudentInfo> list=studentinfodao.getAllStudentInfo();
studentinfotable.getTableHeader().setReorderingAllowed(false);
studentinfotable.setContents(list);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jScrollPane1, gridBagConstraints);
jButton1.setText("\u786e\u5b9a");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jButton1, gridBagConstraints);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int i=0;
while(i<studentinfotable.getRowCount()){
//下面應該用equals
//if(jTextField1.getText().trim()==studentinfotable.getValueAt(i, 1).toString().trim()){
if(jTextField1.getText().trim().equals(studentinfotable.getValueAt(i, 1).toString().trim())){
JOptionPane.showMessageDialog(null, "找到匹配的學號的行,已被選擇成顏色深的行");
studentinfotable.setRowSelectionInterval(i, i);
}
//System.out.println(studentinfotable.getValueAt(i, 1).toString().trim());
i++;
}
if(i>studentinfotable.getRowCount())
JOptionPane.showMessageDialog(null, "沒有找到匹配的學號");
}
private StudentInfoTable studentinfotable;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -