Search Results

Search found 18 results on 1 pages for 'abstracttablemodel'.

Page 1/1 | 1 

  • JTable Delete All Rows Exception

    - by Dimitri
    Hi, I'm trying to delete all entrys from my abstractTableModel. As long as I don't delete the last remaining row, everything works fine, but as soon as I delete this one, I get an ArrayOutOfBoundsException. I'm using a DefaultRowSorter and this seems to be the Exception. Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0 at java.util.Vector.get(Vector.java:694) at graphics.tableModel.MyTableModel.getValueAt(MyTableModel.java:78) at graphics.tableModel.MyTableModel.getColumnClass(MyTableModel.java:90) at javax.swing.table.TableRowSorter.useToString(TableRowSorter.java:224) at javax.swing.DefaultRowSorter.updateUseToString(DefaultRowSorter.java:607) at javax.swing.DefaultRowSorter.sort(DefaultRowSorter.java:556) at javax.swing.DefaultRowSorter.shouldOptimizeChange(DefaultRowSorter.java:1008) at javax.swing.DefaultRowSorter.rowsDeleted(DefaultRowSorter.java:866) at javax.swing.JTable.notifySorter(JTable.java:4262) at javax.swing.JTable.sortedTableChanged(JTable.java:4106) at javax.swing.JTable.tableChanged(JTable.java:4383) at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280) my Code to delete all Rows: public void deleteAll() { int size = data.size()-1; data.clear(); this.fireTableRowsDeleted(0, size); } Same thing happens with simply deleting the last existing row. public void deleteRow(int row) { data.remove(row); } the way i'm calling deleteRow: for (int i = rows.length - 1; i >=0; i--) { tm.deleteRow(rows[i]); } tm.fireTableDataChanged(); thanks for your help

    Read the article

  • create TableModel and populate jTable dynamically

    - by Julia
    Hi all! I want to store the results of reading lucene index into jTable, so that I can make it sortable by different columns. From index I am reading terms with different measures of their frequencies. Table columns are these : [string term][int absFrequency][int docFrequency][double invFrequency] So i in AbstractTableModel I can define column names, but i dont know how to get the Object[][]data with results from the following method: public static void FrequencyMap(Directory indexDir) throws Exception { List<Object>redoviLista = new ArrayList<Object>(); //final Map<String,TermRow> map = new TreeMap<String,TermRow>(); List<String>termList = new ArrayList<String>(); IndexReader iReader = IndexReader.open(indexDir); FilterIndexReader fReader = new FilterIndexReader(iReader); int numOfDocs = fReader.numDocs(); TermEnum terms = fReader.terms(); while (terms.next()){ Term term = terms.term(); String termText = term.text(); termList.add(termText); //Calculating the frequencies int df = iReader.docFreq(term); double idf = 0.0F; idf = Math.log10((double) numOfDocs / df); double tfidf = (df*idf); //Here comes important part Object oneTableRow[] = {termText, df, idf, tfidf}; redoviLista.add(jedanRed); // So i thaught to store them into list, and then later to copy into table, but didnt manage } iReader.close(); // So I need something like this, and i Neeed this array to be stored out of this method Object[][]data = new Object[redoviLista.size()][]; for (int i = 0; i < data.length; i++) { data[i][0] = redoviLista.get(i); } So I am kindda stuck here to proceed to implement AbstractTableModel and populate and display this table .... :/ Please help!

    Read the article

  • java /TableModel of Objects/Update Object"

    - by Tomás Ó Briain
    I've a collection of Stock objects that I'm updating about 10/15 variables for in real-time. I'm accessing each Stock by its ID in the collection. I'm also trying to display this in a JTable and have implemented an AbstractTablemodel. It's not working too well. I've a RowMap that I add each ID to as Stocks are added to the TableModel. To update the prices and variables of all the stocks in the TableModel, I want to send a Stock object to an updateModel(Stock s) method. I can find the relevant row by searching the map, but how do I handle this nicely, so I don't have to start iterating through table columns and comparing the values of the cells to the variables of the object to see whether there are any differences?? Basically, i want to send a Stock object to the TableModel and update cells if there are changes and do nothing if there aren't. Any ideas about how to implement a TableModel that might do this? Any pointeres at all would be appreciated. Thanks.

    Read the article

  • StackOverflowError being caused by a TableModelListener

    - by me_here
    I'm not sure why this is recursing. jTable1.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent evt) { int sum = 0; int i=0; for (i =0 ; i<2; i++){ sum = sum + Integer.parseInt(jTable1.getValueAt(0, i).toString()); } jTable1.setValueAt(sum, 0, 2); } }); The exception is: (it keeps repeating) Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:277) at javax.swing.JTable.convertColumnIndexToModel(JTable.java:2553) at javax.swing.JTable.getValueAt(JTable.java:2695) at testprogram.guitest.TestTableModel$1.tableChanged(TestTableModel.java:63) at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280) at javax.swing.table.AbstractTableModel.fireTableCellUpdated(AbstractTableModel.java:259) at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:650) at javax.swing.JTable.setValueAt(JTable.java:2719) Any help appreciated.

    Read the article

  • JTable Insert row and refresh

    - by user269723
    Hi All, I am trying to create simple application where JTable gets updated and refreshed after data is changed.Structure is as follows. 1)Class Main which contains JFrame,JTable details. 2)SampleTableModel class which extends AbstractTableModel.I am overriding most of the methods.`import javax.swing.table.; import javax.swing.event.; import java.util.*; public class SampleTableModel extends AbstractTableModel { public SampleTableModel(){ // this.addTableModelListener( } String[] columnNames = {"A","B","C","D","E"}; int[][] data = {{1,2,3,4,5},{5,6,7,8,9},{12,13,14,15,16}}; Vector dataVector = new Vector(); public Object getValueAt(int rowIndex,int columnIndex) { return data[rowIndex][columnIndex]; } public int getColumnCount(){ return 5; } public int getRowCount(){ return 3; } public String getColumnName(int columnIndex){ return columnNames[columnIndex]; } public void setValueAt(Object value,int row,int column){ data[row][column] =99; } public void notifyTable(AEMessage message){ /* * This method will be called from another class to update JTable. * */ data[0][1]=999; data[0][2]=8838; data[1][1]=8883; fireTableRowsUpdated(0,3); } } ` As you can see, notifyTable will be called from another class(which is actually a thread-which calls this method frequently) Problem is I don't see data being changed in JTable.I see only the initialized data. In the Main class- I am setting like this- RVJDataTable.setModel(new SampleTableModel());

    Read the article

  • Java, Sychronize JTable and ResultSet

    - by rodion
    Hello, I have JTable, And AbstarctDataModel with fill(ResultSet rs) methods. How to correct synchronize cursor of JTable with ResultSet's cursor? Any links? Thanx a lat. P.S. Please, add AbstractTableModel tag -- Canton of Uri's citizen

    Read the article

  • Cannot bind text field to selected item in JTable in NetBeans

    - by titaniumdecoy
    I am trying to use NetBeans to bind a JTextField to the selected element of a JTable. The JTable gets its data from an AbstractTableModel subclass which returns Cow objects. At present, each Cow object is displayed as a string through its toString method. The binding seems obvious but does not work; the bound value of the text field is always null. I bound the text property of the JTextField in NetBeans to: flowTable[${selectedElement.prefix}] This produces the following line of generated code: org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, flowTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.prefix}"), courseNameTextField, org.jdesktop.beansbinding.BeanProperty.create("text")); What am I doing wrong?

    Read the article

  • JTable row filters updates

    - by Jeff Storey
    Is there a way to tell a JTable's row filter that it should update itself to display the filtered data? I'm currently using the fireTableDataChanged method in the AbstractTableModel but the underlying data for the table isn't actually changing, so this seems like it might be wasteful. The way my filter works is to check if data in the table is in some other list and only display it if it is in that list. So that other list changed and I need to tell the filter to refresh itself. Is fireTableDataChanged the correct way to do this? thanks, Jeff

    Read the article

  • RubyQt Crashing on QTableWidget

    - by gja
    I'm getting some weirdness with QtRuby when using a TableWidget. The table widget loads, but when you click on the elements in the row, the app segfaults and crashes. require 'Qt4' class SimpleModel < Qt::AbstractTableModel def rowCount(parent) return 1 end def columnCount(parent) return 1 end def data(index, role=Qt::DisplayRole) return Qt::Variant.new("Really Long String") if index.row == 0 and index.column == 0 and role == Qt::DisplayRole return Qt::Variant.new end end Qt::Application.new(ARGV) do Qt::TableWidget.new(1, 1) do set_model SimpleModel.new show end exec end The backtrace seems to imply that it is bombing in mousePressEvent #6 0x01624643 in QAbstractItemView::pressed(QModelIndex const&) () from /usr/lib/libQtGui.so.4 #7 0x016306f5 in QAbstractItemView::mousePressEvent(QMouseEvent*) () from /usr/lib/libQtGui.so.4 If I override mousePressEvent and mouseMoveEvent, these kinds of crashes no longer happen. Am I doing something wrong over here, or can I chalk this up as a bug in QtRuby? I'm on fedora11, with the following packages installed: QtRuby-4.4.0-1.fc11.i586 ruby-1.8.6.369-1.fc11.i586 These crashes also happen when running the script on Windows.

    Read the article

  • How to set specific column settings in JTable?

    - by HansDampf
    How can I make my JTable show specific stuff for each column? Can I use an Object for more than one column? I want to have a column showing the date (dd.mm.yyyy) and another to show the time (hh:mm) but as I have it now it only shows the String representation of the Date object as a whole. public class AppointmentTableModel extends AbstractTableModel { ... @Override public Object getValueAt(int rowIndex, int columnIndex) { return appointments.get(rowIndex).getByColumn(columnIndex); } } public class Appointment { ... public Object getByColumn(int columnIndex) { switch (columnIndex) { case 0: return date; case 1: return date; case 2: return sample; case 3: return sample; case 4: return history; case 5: return comment; } return null; } }

    Read the article

  • null pointer exception on list.add

    - by Eric
    I've been working on this one error for a few hours so I thought I'd pick the brains of some pros. I am getting a null pointer exception at the modelData.add(i, es) method. I know from debugging that es isn't null. I'm really confused, thanks. public class EventTableModel extends AbstractTableModel { //private int rowCount = 0; protected List<EventSeat> modelData; private static final int COLUMN_COUNT = 3; private Event e; Event j = GUIpos.m; int i = 1; public EventTableModel(Event e) { this.e = e; try { System.out.println(modelData); for (EventSeat es : e.getEventSeats()) { modelData.add(i, es); i++; } } catch (DataException ex) { Logger.getLogger(EventTableModel.class.getName()).log(Level.SEVERE, null, ex); } }

    Read the article

  • get cells odf a JTable

    - by tuxou
    hi how to display a row of a jtable in a from of JTextField when click on the row, ( I need this to edit the data base from the JTable ) My table model static class TableDataModel extends AbstractTableModel { private List nomColonnes; private List tableau; public TableDataModel(List nomColonnes, List tableau){ this.nomColonnes = nomColonnes; majDonnees(tableau); } public void majDonnees(List nouvellesDonnees){ this.tableau = nouvellesDonnees; fireTableDataChanged(); } public int getRowCount(){ return tableau.size(); } public int getColumnCount(){ return nomColonnes.size(); } public Object getValueAt(int row, int col){ return ((ArrayList)( tableau.get(row))).get(col); } public String getColumnName(int col){ return nomColonnes.get(col).toString(); } public Class getColumnClass(int c) { return getValueAt(0,c).getClass(); } public boolean isCellEditable(int row, int col){ return true; } public void setValueAt(Object value, int row, int col) { ((List)tableau.get(row)).set(col,value); fireTableCellUpdated(row, col); //i suppose i should update the database here } }

    Read the article

  • Using an empty column as a divider in a JTable.

    - by Catalina Island
    I'm trying to use an empty column as a divider between pairs of columns in a JTable. Here's a picture and code for what I have so far. I know I can change the look using a custom TableCellRenderer. Before I go down that road, is there a better way to do this? Any ideas appreciated. import javax.swing.*; import javax.swing.table.*; public class TablePanel extends JPanel { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame f = new JFrame("TablePanel"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new TablePanel()); f.pack(); f.setVisible(true); } }); } public TablePanel() { TableModel dataModel = new MyModel(); JTable table = new JTable(dataModel); table.getColumnModel().getColumn(MyModel.DIVIDER).setMaxWidth(0); JScrollPane jsp = new JScrollPane(table); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); this.add(jsp); } private static class MyModel extends AbstractTableModel { private static final int DIVIDER = 2; private final String[] names = { "A1", "A2", "", "B1", "B2" }; @Override public int getRowCount() { return 32; } @Override public int getColumnCount() { return names.length; } @Override public String getColumnName(int col) { if (col == DIVIDER) return ""; return names[col]; } @Override public Object getValueAt(int row, int col) { if (col == DIVIDER) return ""; return (row + 1) / 10.0; } @Override public Class<?> getColumnClass(int col) { if (col == DIVIDER) return String.class; return Number.class; } } }

    Read the article

  • Java Swing: How to add a CellRenderer for displaying a Date?

    - by HansDampf
    I have a Table: public class AppointmentTableModel extends AbstractTableModel { private int columns; private int rows; ArrayList<Appointment> appointments;... So each row of the table contains one Appointment. public class Appointment { private Date date; private Sample sample; private String comment; private ArrayList<Action> history; public Appointment(Date date, Sample sample, String comment) { this.date = date; this.sample = sample; this.comment = comment; this.history = new ArrayList<Action>(); } public Object getByColumn(int columnIndex) { switch (columnIndex) { case 0: return date;//Date: dd:mm:yyyy case 1: return date;//Time mm:hh case 2: return sample;//sample.getID() int (sampleID) case 3: return sample;//sample.getNumber string (telephone number) case 4: return sample;//sample.getName string (name of the person) case 5: return history;//newst element in history as a string case 6: return comment;//comment as string } return null; I added in comments what this one is going to mean. How would I create CellRenderers to display it like this. table.getColumnModel().getColumn(1).setCellRenderer(new DateRenderer()); I also want to add the whole row to be painted in red when the date is later then the current date. And then another column that holds a JButton to open up another screen with the corresponding Appointment as parameter.

    Read the article

  • I have to select the checkbox two times to check/uncheck in jTable

    - by 117526709403775781607
    I have a jTable code i intend to use, but the problem with it is that when i click on the checkbox once it doesn't select/deselect it, instead i have to click twice. But if i select any other cell in the row except the one containing the checkbox the purpose is solved. HERE IS MY CODE : public class TableSelectionTest extends JFrame implements ListSelectionListener { private final int COLUMN_COUNT = 5; private TblModel model; public TableSelectionTest() { initialize(); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); } private void initialize() { List data = new ArrayList(); for (int i = 0; i < 10; i++) { Object record[] = new Object[COLUMN_COUNT]; record[0] = Boolean.FALSE; for (int j = 1; j < COLUMN_COUNT; j++) { record[j] = new Integer(j); } data.add(record); } model = new TblModel(data); JTable table = new JTable(model); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener (this); JScrollPane scroll = new JScrollPane(table); getContentPane().add(scroll, BorderLayout.CENTER); } public static void main(String[] args) { TableSelectionTest f = new TableSelectionTest(); f.show(); } class TblModel extends AbstractTableModel { private List data; public TblModel(List data) { this.data = data; } public int getColumnCount() { return COLUMN_COUNT; } public int getRowCount() { return data == null ? 0 : data.size(); } public void setValueAt(Object value, int rowIndex, int columnIndex) { getRecord(rowIndex)[columnIndex] = value; super.fireTableCellUpdated(rowIndex, columnIndex); } public Object getValueAt(int rowIndex, int columnIndex) { return getRecord(rowIndex)[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { if(columnIndex == 0) return true; else return false; } public Class getColumnClass(int columnIndex) { if (data == null || data.size() == 0) { return Object.class; } Object o = getValueAt(0, columnIndex); return o == null ? Object.class : o.getClass(); } private Object[] getRecord(int rowIndex) { return (Object[]) data.get(rowIndex); } } public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int index = lsm.getMinSelectionIndex(); if(model.getRecord(index)[0] == Boolean.FALSE) model.setValueAt(Boolean.TRUE, index, 0); else if(model.getRecord(index)[0] == Boolean.TRUE) model.setValueAt(Boolean.FALSE, index, 0); } } } Please reply soon as it is bugging me a lot Thank you in advance :)

    Read the article

  • How to check all check boxes at a click of a button

    - by LivingThing
    I am new to Swing, UI and MVC I have created a code based on MVC. Now my problem is that that in the controller part i have an actioneventlistener which listens to different button clicks. Out of all those buttons i have "select all" and "de-select all". In my view i have a table, one of the column of that table contains "check boxes". Now, when i click the "select-all" button i want to check all the check boxes and with "de-select all" i want to uncheck all of them. Below is my code which is not working. Please tell me what am i doing wrong here. Also, if someone knows a more elagent way please share. Thanks In my view public class CustomerSelectorDialogUI extends JFrame{ public CustomerSelectorDialogUI(TestApplicationUI ownerView, DummyCustomerStore dCStore, boolean modality) { //super(ownerView, modality); setTitle("[=] Customer Selection Dialog [=]"); //setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); custSelectPanel = new JPanel(); buttonPanel = new JPanel(); selectAllButton = new JButton(" Select All "); clearAllButton = new JButton(" Clear All "); applyButton = new JButton(" Apply "); cancelButton = new JButton(" Cancel "); PopulateAndShow(dCStore, Boolean.FALSE); } public void PopulateAndShow(DummyCustomerStore dCStore, Boolean select) { List data = new ArrayList(); for (Customer customer : dCStore.getAllCustomers()) { Object record[] = new Object[COLUMN_COUNT]; record[0] = (select == false) ? Boolean.FALSE : Boolean.TRUE; record[1] = Integer.toString(customer.customerId); record[2] = customer.fullName; data.add(record); } tModel = new TableModel(data); // In the above for loop accoring to user input (i.e click on check all or // uncheck all) i have tried to update the data. As it can be seen that i // have a condition for record[0]. //After the loop, here i have tried several options like validate(). repaint but to no avail customerTable = new JTable(tModel); scrollPane = new JScrollPane(customerTable); setContentPane(this.createContentPane()); setSize(480, 580); setResizable(false); setVisible(true); } private JPanel createContentPane() { custSelectPanel.setLayout(null); customerTable.setDragEnabled(false); customerTable.setFillsViewportHeight(true); scrollPane.setLocation(10, 10); scrollPane.setSize(450,450); custSelectPanel.add(scrollPane); buttonPanel.setLayout(null); buttonPanel.setLocation(10, 480); buttonPanel.setSize(450, 100); custSelectPanel.add(buttonPanel); selectAllButton.setLocation(0, 0); selectAllButton.setSize(100, 40); buttonPanel.add(selectAllButton); clearAllButton.setLocation(110, 0); clearAllButton.setSize(100, 40); buttonPanel.add(clearAllButton); applyButton.setLocation(240, 0); applyButton.setSize(100, 40); buttonPanel.add(applyButton); cancelButton.setLocation(350, 0); cancelButton.setSize(100, 40); buttonPanel.add(cancelButton); return custSelectPanel; } } Table Model private class TableModel extends AbstractTableModel { private List data; public TableModel(List data) { this.data = data; } private String[] columnNames = {"Selected ", "Customer Id ", "Customer Name " }; public int getColumnCount() { return COLUMN_COUNT; } public int getRowCount() { return data == null ? 0 : data.size(); } public String getColumnName(int col) { return columnNames[col]; } public void setValueAt(Object value, int rowIndex, int columnIndex) { getRecord(rowIndex)[columnIndex] = value; super.fireTableCellUpdated(rowIndex, columnIndex); } private Object[] getRecord(int rowIndex) { return (Object[]) data.get(rowIndex); } public Object getValueAt(int rowIndex, int columnIndex) { return getRecord(rowIndex)[columnIndex]; } public Class getColumnClass(int columnIndex) { if (data == null || data.size() == 0) { return Object.class; } Object o = getValueAt(0, columnIndex); return o == null ? Object.class : o.getClass(); } public boolean isCellEditable(int row, int col) { if (col > 0) { return false; } else { return true; } } } } A Views Action Listener class CustomerSelectorUIListener implements ActionListener{ CustomerSelectorDialogUI custSelectView; Controller controller; public CustomerSelectorUIListener (Controller controller, CustomerSelectorDialogUI custSelectView) { this.custSelectView = custSelectView; this.controller = controller; } @Override public void actionPerformed(ActionEvent e) { String actionEvent = e.getActionCommand(); else if ( actionEvent.equals( "clearAllButton" ) ) { controller.checkButtonControl(false); } else if ( actionEvent.equals( "selectAllButton" ) ) { controller.checkButtonControl(true); } } } Main Controller public class Controller implements ActionListener{ CustomerSelectorDialogUI selectUI; DummyCustomerStore store; public Controller( DummyCustomerStore store, TestApplicationUI appUI ) { this.store = store; this.appUI = appUI; appUI.ButtonListener( this ); } @Override public void actionPerformed(ActionEvent event) { String viewAction = event.getActionCommand(); if (viewAction.equals("TEST")) { selectUI = new CustomerSelectorDialogUI(appUI, store, true); selectUI.showTextActionListeners(new CustomerSelectorUIListener( this, selectUI ) ); selectUI.setVisible( true ); } } public void checkButtonControl (Boolean checkAll) { selectUI.PopulateAndShow(store, checkAll); } }

    Read the article

1