你是說線程優(yōu)先級么,可以設置的一般級別為5,設高點就可以了
創(chuàng)新互聯(lián)專注于港閘網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供港閘營銷型網(wǎng)站建設,港閘網(wǎng)站制作、港閘網(wǎng)頁設計、港閘網(wǎng)站官網(wǎng)定制、小程序設計服務,打造港閘網(wǎng)絡公司原創(chuàng)品牌,更為您提供港閘網(wǎng)站排名全網(wǎng)營銷落地服務。
import?java.awt.BorderLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JTable;
import?javax.swing.JTextField;
import?javax.swing.event.TableModelEvent;
import?javax.swing.event.TableModelListener;
public?class?JTableTest?extends?JFrame?{
private?JPanel?searchPanel;
private?JTextField?searchField;
private?JButton?searchButton;
private?JTable?table;
private?TestTableModel?tableModel;
public?JTableTest()?{
super("Simple?JTable?Test");
setSize(400,?300);
searchPanel?=?new?JPanel();
searchField?=?new?JTextField(20);
searchPanel.add(searchField);
searchButton?=?new?JButton("搜索");
searchButton.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?event)?{
table.getSelectionModel().clearSelection();
doSearch();
}
});
searchPanel.add(searchButton);
getContentPane().add(searchPanel,?BorderLayout.NORTH);
tableModel?=?new?TestTableModel();
tableModel.addTableModelListener(new?TableModelListener()?{
@Override
public?void?tableChanged(TableModelEvent?e)?{
if?(tableModel.getHitRowCount()??0)?{
table.setRowSelectionInterval(0,?tableModel.getHitRowCount()?-?1);
}
}
});
table?=?new?JTable(tableModel);
JScrollPane?jsp?=?new?JScrollPane(table);
getContentPane().add(jsp,?BorderLayout.CENTER);
}
private?void?doSearch()?{
tableModel.doSearch(searchField.getText());
}
public?static?void?main(String[]?args)?{
JTableTest?self?=?new?JTableTest();
self.setVisible(true);
}
}
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.List;
import?javax.swing.table.AbstractTableModel;
public?class?TestTableModel?extends?AbstractTableModel?{
private?ListString?data?=?Arrays.asList("王二",?"王二小",?"張三",?"張三豐",?"李四",?"李四光");
private?ListInteger?searchHitRows?=?new?ArrayListInteger();
@Override
public?int?getRowCount()?{
return?data.size();
}
@Override
public?int?getColumnCount()?{
return?1;
}
@Override
public?String?getColumnName(int?column)?{
return?"姓名";
}
@Override
public?Object?getValueAt(int?rowIndex,?int?columnIndex)?{
return?rowIndex??data.size()???data.get(rowIndex)?:?null;
}
public?void?doSearch(String?key)?{
searchHitRows.clear();
if?(key?==?null?||?"".equals(key))
return;
for?(int?i?=?0;?i??data.size();?i++)?{
String?value?=?data.get(i);
if?(value.indexOf(key)??0)
continue;
int?j?=?0;
for?(j?=?i?-?1;?j?=?0;?j--)?{
String?valueJ?=?data.get(j);
if?(valueJ.indexOf(key)?=?0)
break;
}
String?temp?=?data.get(j?+?1);
data.set(j?+?1,?value);
data.set(i,?temp);
searchHitRows.add(Integer.valueOf(j?+?1));
}
fireTableDataChanged();
}
public?int?getHitRowCount()?{
return?searchHitRows.size();
}
}
不是很明白你的要求。具體的操作是怎樣的的呢?
假設數(shù)據(jù)庫中有個學生表:
學號? 姓名? 年齡
001? 張三? 20
002??李四? 21
假設按姓名搜索,輸入搜索條件“張”:
情況1、根據(jù)搜索條件直接搜索數(shù)據(jù)庫記錄(通常都是這樣搜索),那從數(shù)據(jù)庫搜索出的記錄就只有姓名包含“張”的記錄,然后JTable中也就只展示這些記錄,就無所謂置頂不置頂啦。
情況2、只是根據(jù)搜索條件在當前JTable展示的數(shù)據(jù)中搜索,代碼如下:
import?java.awt.BorderLayout;
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JTable;
import?javax.swing.JTextField;
import?javax.swing.border.EmptyBorder;
import?javax.swing.event.TableModelEvent;
import?javax.swing.event.TableModelListener;
public?class?JTableTest?extends?JFrame?{
private?JPanel?searchPanel;
private?JTextField?numField;
private?JButton?searchByNumButton;
private?JTextField?nameField;
private?JButton?searchByNameButton;
private?JTable?table;
private?TestTableModel?tableModel;
public?JTableTest()?{
super("Simple?JTable?Test");
setSize(400,?300);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
searchPanel?=?new?JPanel();
searchPanel.setBorder(new?EmptyBorder(3,?3,?3,?3));
searchPanel.setLayout(new?GridLayout(2,?3,?2,?3));
searchPanel.add(new?JLabel("學號"));
numField?=?new?JTextField(20);
searchPanel.add(numField);
searchByNumButton?=?new?JButton("按學號搜索");
searchByNumButton.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?event)?{
table.getSelectionModel().clearSelection();
tableModel.doSearchByNum(numField.getText());
}
});
searchPanel.add(searchByNumButton);
searchPanel.add(new?JLabel("姓名"));
nameField?=?new?JTextField(20);
searchPanel.add(nameField);
searchByNameButton?=?new?JButton("按姓名搜索");
searchByNameButton.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?event)?{
table.getSelectionModel().clearSelection();
tableModel.doSearchByName(nameField.getText());
}
});
searchPanel.add(searchByNameButton);
getContentPane().add(searchPanel,?BorderLayout.NORTH);
tableModel?=?new?TestTableModel();
tableModel.addTableModelListener(new?TableModelListener()?{
@Override
public?void?tableChanged(TableModelEvent?e)?{
if?(tableModel.getHitRowCount()??0)?{
table.setRowSelectionInterval(0,?tableModel.getHitRowCount()?-?1);
}
}
});
table?=?new?JTable(tableModel);
JScrollPane?jsp?=?new?JScrollPane(table);
getContentPane().add(jsp,?BorderLayout.CENTER);
}
public?static?void?main(String[]?args)?{
JTableTest?self?=?new?JTableTest();
self.setVisible(true);
}
}
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.List;
import?javax.swing.table.AbstractTableModel;
public?class?TestTableModel?extends?AbstractTableModel?{
private?ListStudent?data?=?Arrays.asList(new?Student("001",?"王二",?20),?new?Student("002",
"王二小",?19),?new?Student("003",?"張三",?20),?new?Student("004",?"張三豐",?21),?new?Student("005",
"李四",?21),?new?Student("006",?"李四光",?19));
private?ListInteger?searchHitRows?=?new?ArrayListInteger();
@Override
public?int?getRowCount()?{
return?data.size();
}
@Override
public?int?getColumnCount()?{
return?3;
}
@Override
public?String?getColumnName(int?column)?{
if?(column?==?0)
return?"學號";
else?if?(column?==?1)
return?"姓名";
return?"年齡";
}
@Override
public?Object?getValueAt(int?rowIndex,?int?columnIndex)?{
Student?student?=?data.get(rowIndex);
if?(columnIndex?==?0)
return?student.getNum();
else?if?(columnIndex?==?1)
return?student.getName();
return?student.getAge();
}
/**?按姓名搜索?*/
public?void?doSearchByName(String?key)?{
searchHitRows.clear();
if?(key?==?null?||?"".equals(key))
return;
for?(int?i?=?0;?i??data.size();?i++)?{
Student?studentI?=?data.get(i);
String?value?=?studentI.getName();
if?(value.indexOf(key)??0)
continue;
int?j?=?0;
for?(j?=?i?-?1;?j?=?0;?j--)?{
Student?studentJ?=?data.get(j);
String?valueJ?=?studentJ.getName();
if?(valueJ.indexOf(key)?=?0)
break;
}
Student?temp?=?data.get(j?+?1);
data.set(j?+?1,?studentI);
data.set(i,?temp);
searchHitRows.add(Integer.valueOf(j?+?1));
}
fireTableDataChanged();
}
/**?按學號搜索?*/
public?void?doSearchByNum(String?key)?{
searchHitRows.clear();
if?(key?==?null?||?"".equals(key))
return;
for?(int?i?=?0;?i??data.size();?i++)?{
Student?studentI?=?data.get(i);
String?value?=?studentI.getNum();
if?(value.indexOf(key)??0)
continue;
int?j?=?0;
for?(j?=?i?-?1;?j?=?0;?j--)?{
Student?studentJ?=?data.get(j);
String?valueJ?=?studentJ.getNum();
if?(valueJ.indexOf(key)?=?0)
break;
}
Student?temp?=?data.get(j?+?1);
data.set(j?+?1,?studentI);
data.set(i,?temp);
searchHitRows.add(Integer.valueOf(j?+?1));
}
fireTableDataChanged();
}
public?void?setData(ListStudent?data)?{
if?(data?==?null)
throw?new?IllegalArgumentException("參數(shù)data不能為null。");
this.data?=?data;
fireTableDataChanged();
}
public?int?getHitRowCount()?{
return?searchHitRows.size();
}
}
從數(shù)據(jù)庫查詢出記錄后,轉成Student對象列表調(diào)用TestTableModel的setData設置表格的數(shù)據(jù)。
查數(shù)據(jù)庫的時候按時間倒序取出來就好了啊?
select * from tab where **=** order by publishTime desc;