Results 1 to 1 of 1
- 02-08-2010, 08:15 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 68
- Rep Power
- 0
deleting the data in the column model
I've been searching at google, but I cant find any resources that can resolve this one. I can only delete the column, but I dont know what will happen on its data, then I saw this - Removing a Column from a JTable Component | Example Depot, I found out that the data in the column still lying on its model, so I need to delete it too..Java Code:public class JTableDeletingSelectedColumns extends JFrame { private JTable table; private JPanel panel; private JScrollPane scroll; private JButton deleteColumnButton; private DefaultTableModel model; public JTableDeletingSelectedColumns() { initializeInventory(); } private void initializeInventory() { panel = new JPanel(); deleteColumnButton = new JButton("Delete"); panel.setLayout(null); final String[] columnNames = {"Name", "Surname", "Age"}; final Object[][] data = {{"Jhon", "Java", "23"}, {"Stupid", "Stupido", "500"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"}, {"Max", "Dumbass", "10"}, {"Melanie", "Martin", "500"}, {"Jollibe", "Mcdonalds", "15"}}; model = new DefaultTableModel(data, columnNames); table = new JTable(model); table.setRowSelectionAllowed(true); scroll = new JScrollPane(table); scroll.setBounds(0, 100, 900, 500); deleteColumnButton.setBounds(50, 50, 150, 20); deleteColumnButton.addActionListener(new DeleteActionListener()); panel.add(deleteColumnButton); panel.add(scroll); getContentPane().add(panel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Inventory Window"); setSize(900, 900); setLocationRelativeTo(null); setVisible(true); } private class DeleteActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (deleteColumnButton.equals(e.getSource())) { String columnName = JOptionPane.showInputDialog(null, "Please Enter The Column That Will Be Deleted."); int columnIndex = 0; for (int x = 0; x < table.getColumnCount(); x++) { if (columnName.equals(table.getColumnName(x))) { columnIndex = x; table.removeColumn(table.getColumnModel().getColumn(columnIndex)); } } } } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new JTableDeletingSelectedColumns(); } }); } }
but I cant compile that code properly , now Im getting frustrated how to delete the value in my column model.. help please..
Similar Threads
-
Dynamic data model in JComboBox
By agreed in forum AWT / SwingReplies: 5Last Post: 11-15-2009, 08:30 PM -
Filter table model by data in specific column
By ribbs2521 in forum New To JavaReplies: 9Last Post: 10-29-2009, 04:41 AM -
how to move an entire column with data to another index in same sheet using jxl
By katkamravi in forum Advanced JavaReplies: 0Last Post: 07-24-2009, 08:58 AM -
Apache/POI.jar is there any option to enable data/column filters using poi.jar.
By pothraj in forum New To JavaReplies: 0Last Post: 12-18-2008, 07:13 AM -
Data from a model class won't show up in the table
By ayampanggang in forum AWT / SwingReplies: 3Last Post: 11-27-2008, 08:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks