请问各位大虾
如何将JTable中的某一列进行彻底的删除?
谢谢了
如何将JTable中的某一列进行彻底的删除?
谢谢了
解决方案 »
- 传闻:Java IO相对C/C++,效率为什么低??为嘛!!??
- 开发网站时,静态方法占用内存吧?
- 反射 类型的判断
- 一个代码问题,请解释!谢谢!
- 我想在java应用中实现 宏 的功能,不知道从何下手。希望朋友们指点一下。
- //请大家帮我看一下两者之间的区别何在?
- 怎么控制输出流格式
- 关于JDialog
- where can download emulator(POSE)'s ROMs. Free is better
- 请问通过纯jdbc能否联 sqlserver7.0,注意不是通过jdbc-odbc桥,如果能的话,driver在哪里下载?连接的语句怎么写?
- Graphics里面没有清除画图板的方法。怎么实现?
- 请高手赐教!很急!
TableColumn firstNameColumn = table.getColumn("ColumnName");
--------------------------------------------------------------------------------
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Test extends JFrame {
JTable table = new JTable(
new Object[][] {
{"Mouse", "Mighty", "M." },
{"Mouse", "Polly", "A." },
{"Doright", "Dudley", "L." }
},
new Object[] {
"Last Name", "First Name", "Middle Initial"
}
);
public Test() {
Container cp = getContentPane();cp.add(new JScrollPane(table), BorderLayout.CENTER);
cp.add(new ControlPanel(), BorderLayout.NORTH);
}
class ControlPanel extends JPanel {
private JCheckBox checkBox = new JCheckBox(
"First Name Column Showing");
public ControlPanel() {
final TableColumnModel tcm = table.getColumnModel();
final TableColumn firstNameColumn =
table.getColumn("First Name");checkBox.setSelected(true);
add(checkBox);checkBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if(checkBox.isSelected()) {
tcm.addColumn(firstNameColumn);
tcm.moveColumn(2,1);
}
else {
tcm.removeColumn(firstNameColumn);
}
table.sizeColumnsToFit(-1);
}
});
}
}
public static void main(String args[]) {
GJApp.launch(
new Test(), "Showing/Hiding Columns",300,300,450,175);
}
}
class GJApp extends WindowAdapter {
static private JPanel statusArea = new JPanel();
static private JLabel status = new JLabel(" ");
static private ResourceBundle resources;public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h) {
launch(f,title,x,y,w,h,null);
}
public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h,
String propertiesFilename) {
f.setTitle(title);
f.setBounds(x,y,w,h);
f.setVisible(true);statusArea.setBorder(BorderFactory.createEtchedBorder());
statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusArea.add(status);
status.setHorizontalAlignment(JLabel.LEFT);f.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);if(propertiesFilename != null) {
resources = ResourceBundle.getBundle(
propertiesFilename, Locale.getDefault());
}f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
static public JPanel getStatusArea() {
return statusArea;
}
static public void showStatus(String s) {
status.setText(s);
}
static Object getResource(String key) {
if(resources != null) {
return resources.getString(key);
}
return null;
}
}