StackOverflowError in JTable using DefaultTableModel

Hi:
I have a JTable using DefaultTableModel. I also have a tableChanged function that puts values into columns based on values from other columns. Initially, I set up the table with one row, then a popup will call the addRow function on DefaultTableModel. Here's my addRow function:
private void addRow() {
try {
String [] newString = new String[10];
for (int i=0; i<10; i++)
newString[i] = "";
defaultTableModel.addRow(newString);
} catch (java.lang.StackOverflowError seiou){
As you can see from my catch statement, I keep getting a problem with a StackOverflowError when I enter values into the table; when I add a row, it kicks me out of the program. I am currently changing and checking values in the table with:
defaultTableModel.setValueAt(); and
defaultTableModel.getValueAt();
Any suggestions?

Hi:
I have a JTable using DefaultTableModel. I also have a tableChanged function that puts values into columns based on values from other columns. Initially, I set up the table with one row, then a popup will call the addRow function on DefaultTableModel. Here's my addRow function:
private void addRow() {
try {
String [] newString = new String[10];
for (int i=0; i<10; i++)
newString[i] = "";
defaultTableModel.addRow(newString);
} catch (java.lang.StackOverflowError seiou){
As you can see from my catch statement, I keep getting a problem with a StackOverflowError when I enter values into the table; when I add a row, it kicks me out of the program. I am currently changing and checking values in the table with:
defaultTableModel.setValueAt(); and
defaultTableModel.getValueAt();
Any suggestions?

Similar Messages

  • Deleting rows from a JTable using DefaultTableModel

    First of all, is it possible to remove a row of information from a table that uses the DefaultTableModel?
    I have created a table using the default table model as follows:
              tblPhoneNumbers = new JTable(new DefaultTableModel(
                        new Object[][]{{"",""}},
                        new Object[]{"Number", "Type"})
    I then have a button that when clicked is supposed to remove the selected row from the table:
         protected void btnRemovePhoneActionPerformed(ActionEvent evt) {
              DefaultTableModel phoneDm = (DefaultTableModel) tblPhoneNumbers.getModel();
              int selectedRow = tblPhoneNumbers.getSelectedRow();
              int numRows = tblPhoneNumbers.getRowCount();
              if(selectedRow >= 0 && selectedRow < numRows-1)
                   phoneDm.removeRow(selectedRow);
    By calling the removeRow() method it is updating the table in the dialog just fine, and shifting all of the information up to where it belongs. But if for example I remove the first row, and then try to access the information in the first row, the information I supposedly just removed is still there.
    Am I supposed to be firing an event on removing that row to manually update the data in the table? If so, how would I do that?
    It seems like this should be really easy to do I just can't for the life of me figure out what I'm doing wrong.
    Thanks

    But if for example I remove the first row, and then try to access the
    information in the first row, the information I supposedly just removed is still there.Never seen that before.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

  • Deleting a row from a JTable using a custom TableModel

    Before I waste any of your time I would like to go ahead and just say that I have searched through the forum using "delete row from Jtable" as the search keywords and while I have found very closely related issues, they have not solved my problem. I have found code postings by carmickr and his arguments as to why we should use DefaultTableModel instead of having created our own custom TableModel, and while I do agree, I just am not quite confident enough in applying it to my scenario. See I am reading from a file a bunch of Contractor objects and I am stuffing it into an arraylist which I am using in the following code posting to populate my TableModel which the JTable object in the gui then uses.
    My problem is that everything works except when I delete and when I delete I understand that the index is changing because I just removed a row from the arraylist object. Suppose I have 33 rows displaying in the GUI. Now after I delete say row #23, the delete function works and dutifuly the row disappears from the table, but if I try to delete a row say...the last row, it does not work and throws me an IndexOutOfBoundsException which totally makes sense. My question is how do I go about fixing it? Do I have to do something with the setRowCount method?
    Any help is appreciated.
    Cheers,
    Surya
    * ContractorTableModel.java
    * Created on January 12, 2006, 11:59 PM
    package code.suncertify.gui;
    import java.util.ArrayList;
    import java.util.logging.Logger;
    import javax.swing.table.AbstractTableModel;
    import code.suncertify.db.Contractor;
    * @author Surya De
    * @version 1.0
    public class ContractorTableModel extends AbstractTableModel {
         * The Logger instance. All log messages from this class are routed through
         * this member. The Logger namespace is <code>sampleproject.gui</code>.
        private Logger log = Logger.getLogger("code.gui");
         * An array of <code>String</code> objects representing the table headers.
        private String [] headerNames = {"Record Number", "Contractor Name",
        "Location", "Specialties","Size", "Rate",
        "Owner"};
         * Holds all Contractor instances displayed in the main table.
        private ArrayList <Object> contractorRecords = new ArrayList<Object>(5);
         * Returns the column count of the table.
         * @return An integer indicating the number or columns in the table.
        public int getColumnCount() {
            return this.headerNames.length;
         * Returns the number of rows in the table.
         * @return An integer indicating the number of rows in the table.
        public int getRowCount() {
            return this.contractorRecords.size();
         * Gets a value from a specified index in the table.
         * @param row An integer representing the row index.
         * @param column An integer representing the column index.
         * @return The object located at the specified row and column.
        public Object getValueAt(int row, int column) {
            Object [] temp = (Object[]) this.contractorRecords.get(row);
            return temp[column];
         * Sets the cell value at a specified index.
         * @param obj The object that is placed in the table cell.
         * @param row The row index.
         * @param column The column index.
        public void setValueAt(Object obj, int row, int column) {
            Object [] temp = (Object []) this.contractorRecords.get(row);
            temp [column] = obj;
         * Returns the name of a column at a given column index.
         * @param column The specified column index.
         * @return A String containing the column name.
        public String getColumnName(int column) {
            return headerNames[column];
         * Given a row and column index, indicates if a table cell can be edited.
         * @param row Specified row index.
         * @param column Specified column index.
         * @return A boolean indicating if a cell is editable.
        public boolean isCellEditable(int row, int column) {
            return false;
         * Adds a row of Contractor data to the table.
         * @param specialty
         * @param recNo The record number of the row in question.
         * @param name The name of the contractor.
         * @param location Where the contractor is located
         * @param size Number of workers for the contractor
         * @param rate The contractor specific charge rate
         * @param owner Name of owner
        public void addContractorRecord(int recNo, String name,
                String location, String specialty,
                int size, float rate, String owner) {
            Object [] temp = {new Integer(recNo), name,
            location, specialty, new Integer(size),
            new Float(rate), owner};
            this.contractorRecords.add(temp);
            fireTableDataChanged();
         * Adds a Contractor object to the table.
         * @param contractor The Contractor object to add to the table.
        public void addContractorRecord(Contractor contractor) {
            Object [] temp = {new Integer(contractor.getRecordNumber()),
            contractor.getName(), contractor.getLocation(),
            contractor.getSpecialties(), new Integer(contractor.getSize()),
            new Float(contractor.getRate()), contractor.getCustomerID()};
            this.contractorRecords.add(temp);
            fireTableDataChanged();
         * Deletes a row of Contractor data to the table.
         * @FIXME Now that I deleted a row then I will have to reset the internal structure so that I can delete again
         * @param recNo The record number of the row in question.
        public void deleteContractorRecord(int recNo) {
            contractorRecords.remove(recNo - 1);
            fireTableRowsDeleted(recNo -1, recNo - 1);
    }

    Wow that was a very quick response. Thanks camickr. I am only trying to delete a single row. I do not know how to go about posting a test program for the code I have posted above because honestly the gui itself is 800 lines of code, and then the file reading class is quite funky in itself. I can maybe email you the entire Netbeans project including code so if you are using Netbeans 5 RC2 you can run the code and see for yourself, but that would not be considerate of me.
    See I am trying to delete any row at any time...but only one at a time not multiple rows...so if a user decides to delete row 23 and then tries to delete the last row which happens to be row 33 in my case, my setup should be smart enough to still allow to delete the row.

  • How to remove a row from a jtable with DefaultTableModel

    Hi to all,]
    I want to remove a row from jtable. I am using DefaultTableModel.
    I have got some example but every example is given with AbstractTableModel
    Please help me...
    Thanks and Regards

    I want to remove a row from jtable. I am using DefaultTableModel.How do you program without reading the API.
    The name of the method you use is "removeRow". How hard is that to find by reading the API?
    Not only do you not bother to read the API, you don't even bother to read and respond to your old postings when you get help:
    http://forum.java.sun.com/thread.jspa?threadID=5137773
    http://forum.java.sun.com/thread.jspa?threadID=5134667
    http://forum.java.sun.com/thread.jspa?threadID=5131162
    Your on your own in the future.

  • Updating a JTable using a JTable

    I am looking to update an empty JTable using the data from a JTable containing a set of data.
    I am aware that addRow can be used with the DefaultTableModel from previous discussions on this forum, but I have found this call isn't available when using AbstractTableModel.
    The reason I have been having some problems with this as it is necessary for the AbstractTableModel to be used in the context of the GUI, and I am asking if there is a way to solve this using the AbstractTableModel?
    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.

    I am using an AbstractTableModel for both the data table and the table showing all currently and previously selected rows.No you aren't. You can't create an Abstract class because not all the methods are implements. You are using a class that extends AbstractTableModel.
    So why not use the DefaultTableModel and make your life simple?

  • Stopping cell editing in a JTable using a JComboBox editor w/ AutoComplete

    Hi there! Me again with more questions!
    I'm trying to figure out the finer parts of JTable navigation and editing controls. It's getting a bit confusing. The main problem I'm trying to solve is how to make a JTable using a combo box editor stop editing by hitting the 'enter' key in the same fashion as a JTextField editor. This is no regular DefaultCellEditor though -- it's one that uses the SwingX AutoCompleteDecorator. I have an SSCCE that demonstrates the issue:
    import java.awt.Component;
    import java.awt.EventQueue;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableModel;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    public class AutoCompleteCellEditorTest extends JFrame {
      public AutoCompleteCellEditorTest() {
        JTable table = new JTable();
        Object[] items = {"A", "B", "C", "D"};
        TableModel tableModel = new DefaultTableModel(2, 2);
        table.setModel(tableModel);
        table.getColumnModel().getColumn(0).setCellEditor(new ComboCellEditor(items));
        getContentPane().add(table);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
      private class ComboCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox comboBox;
        public ComboCellEditor(Object[] items) {
          this.comboBox = new JComboBox(items);
          AutoCompleteDecorator.decorate(this.comboBox);
        public Object getCellEditorValue() {
          return this.comboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          comboBox.setSelectedItem(value);
          return comboBox;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
            new AutoCompleteCellEditorTest().setVisible(true);
    }Problem 1: Starting to 'type' into the AutoCompleteDecorate combo box doesn't cause it to start editing. You have to hit F2, it would appear. I've also noticed this behaviour with other JComboBox editors. Ideally that would be fixed too. Not sure how to do this one.
    Problem 2: After editing has started (say, with the F2 key), you may start typing. If you type one of A, B, C, or D, the item appears. That's all good. Then you try to 'complete' the edit by hitting the 'enter' key... and nothing happens. The 'tab' key works, but it puts you to the next cell. I would like to make the 'enter' key stop editing, and stay in the current cell.
    I found some stuff online suggesting you take the input map of the table and set the Enter key so that it does the same thing as tab. Even though that's not exactly what I desired (I wanted the same cell to be active), it didn't work anyway.
    I also tried setting a property on the JComboBox that says that it's a table cell editor combo box (just like the DefaultCellEditor), but that didn't work either. I think the reason that fails is because the AutoCompleteDecorator sets isEditable to true, and that seems to stop the enter key from doing anything.
    After tracing endless paths through processKeyBindings calls, I'm not sure I'm any closer to a solution. I feel like this should be a fairly straightforward thing but I'm having a fair amount of difficulty with it.
    Thanks for any direction you can provide!

    Hi Jeanette,
    Thanks for your advice. I looked again at the DefaultCellEditor. You are correct that I am not firing messages for fireEditingStopped() and fireEditingCancelled(). Initially I had copied the behaviour from DefaultCellEditor but had trimmed it out. I assumed that since I was extending AbstractCellEditor and it has them implemented correctly that I was OK. But I guess that's not the case! The problem I'm having with implementing the Enter key stopping the editing is that:
    1) The DefaultCellEditor stops cell editing on any actionPerformed. Based on my tests, actionPerformed gets called whenever a single key gets pressed. I don't want to end the editing on the AutoCompleteDecorated box immediately -- I'd like to wait until the user is happy with his or her selection and has hit 'Enter' before ending cell editing. Thus, ending cell editing within the actionPerformed listener on the JComboBox (or JXComboBox, as I've made it now) will not work. As soon as you type a single key, if it is valid, the editing ends immediately.
    2) I tried to add a key listener to the combo box to pick up on the 'Enter' key and end the editing there. However, it appears that the combo box does not receive the key strokes. I guess they're going to the AutoCompleteDecorator and being consumed there so the combo box does not receive them. If I could pick up on the 'Enter' key there, then that would work too.
    I did more reading about input maps and action maps last night. Although informative, I'm not sure how far it got me with this problem because if the text field in the AutoCompleteDecorator takes the keystroke, I'm not sure how I'm going to find out about it in the combo box.
    By the way, when you said 'They are fixed... in a recent version of SwingX', does that mean 1.6.2? That's what I'm using.
    Thanks!
    P.S. - Maybe I should create a new question for this? I wanted to mark your answer as helpful but I already closed the thread by marking the answer to the first part as correct. Sorry!
    Edited by: aardvarkk on Jan 27, 2011 7:41 AM - Added SwingX versioning question.

  • How to assign values to JTable using mysql database

    how to assign value to JTable using mysql...

    Search the forum. You use the values of the "ResultSet" to create a "DefaultTableModel" which you then add to the "JTable".
    I'll let you pick the search keywords to use, which I've suggested above. You can also throw in my userid if you want to specifically look for my solution.

  • How to add rows using DefaultTableModel?

    I'm trying to figure out the ins-and-outs of creating a dynamic table.
    I looked for a tutorial, but none of the example programs I found dealt with my particular issue, nor did they explain anything.
    For instance, most of the examples looked like this:
            table = new JTable();
            defaultModel = new DefaultTableModel(10,5);
            setModel(defaultModel);But that doesn't work for me -- I'm creating a class that EXTENDS DefaultTableModel, and so if I want to send in parameters, I have a problem.
              public MyTableModel() {
                            super(data, columnNames);
                    ...The above code complains that "you can't access data or columnNames until you call super()!"
    But I've seen plenty of example code that DOES send in parameters to super(). How do they get away with that? Is it because they are parameters to the constructor, whereas private/public members of the class are somehow different?
    I thought a variable is a variable -- why is one allowed but not the other?
    Lastly, I'm trying to figure out, practically speaking, how to load a database with X items, and be able to add rows later. Does that mean I need to use a vector for my data instead of Object[][]?
    I've seen BOTH AbstractDataModel and DefaultTableModel used with dynamic tables -- is there any difference between them as far as dynamic tables are concerned?
    I was under the impression that I needed to "switch" from ADM to DTM if I wanted to be able to add rows to my table at runtime.
    Here are some references to previous discussions I found/participated in on this topic:
    http://forum.java.sun.com/thread.jspa?threadID=5224966
    http://forum.java.sun.com/thread.jspa?threadID=439141&start=0&tstart=0
    Thanks in advance for any help,
    Matthew

    -> I'm creating a class that EXTENDS DefaultTableModel, and so if I want to send in parameters, I have a problem
    Well, you would pass in the data and columnNames as parameter when you create your table model.
    -> Lastly, I'm trying to figure out, practically speaking, how to load a
    -> database with X items, and be able to add rows later. Does that
    -> mean I need to use a vector for my data instead of Object[][]?
    You just said you extended DefaultTableModel. Well you don't need to do anything it already manages the data for you. You just use the methods provided to update and change the data.
    -> I've seen BOTH AbstractDataModel and DefaultTableModel used with dynamic tables
    No you haven't. You really don't understand what an AbstractDataModel is do you? Its nothing. You can't use it. It doesn't have any storage for the data, and since there is no data storage you can't access the data or change it. You can't even create an AbstractTableModel. Read your Java text on what an Abstract class it.
    The DefaultTableModel extends the AbstractTableModel to provide data storage and ways to get the data and change the data. It notifies the table when any change is made to the data so the table can repaint itself.
    -> How to add rows using DefaultTableModel?
    Finally, the DTM provides methods that make the model dynamic. Methods for adding and removing rows or adding and removing columns. Read the API for more information.
    If you still don't understand how how the methods work then search the forum for examples that use the methods you don't understand. I've posted an example the uses the methods required to add rows or columns.

  • Deleting a row from a JTable using AbstractTableModel

    Hi,
    Can someone please help me on how should i go about deleting a row in a jtable using the AbstractTableModel. Here i know how to delete it by using vector as one of the elements in the table. But i want to know how to delete it using an Object[][] as the row field.
    Thanks for the help

    Hi,
    I'm in desperate position for this please help

  • Sorting Columns in JTable Using Different Comparators

    Is there any way to sort each column in a JTable using different comparators?

    you'll have to write your own tableSorter

  • Is it posiible to paging up paging down in Jtable using Default Table Model

    Hi All!
    Is it possible to do Page up and Page down in JTable using Default Tble Model?
    Kindly reply!

    yes
    it is posiible to paging up paging down in Jtable using Default Table Model. just go thru the JAVA API you will get the results.

  • Displaying JTable using GridBagLayout

    Hii Javaties
    I am displaying all my GUI using GridBagLayout Manager.
    But i dont know , how to add a JTable using GridBagLayout manager.
    I[b] want tht each column of the JTable be displayed in each cell .
    i.e column 1 should be displayed at position 1,4
    Can anybody guide me .
    Thanx

    Perhaps what you are looking for is Custom Editors or Renderers?

  • Sorting JTable using keyboard

    Hi all,
    Is it possible to sort JTable using keyboard? There is a key to get the focus to a column header by clicking the key F8. I don't find any key to sort the table based on the column which is in focus. Is there any solution for this?
    Thanks,
    Ganesh

    You miss the point of that link, there is no need to write any custom code.
    I have already tried to implement Keyboard listener of JTableHeader which must be similar to using Key Bindings.You should NOT use a KeyListener, Swing was designed to use KeyBindings
    The problem I am facing is that I am unable to find the column which got the key strokeYou don't have to write any code, the functionality you want is already supported with a Key Binding. Just use the "space" key.
    If you don't like the space key, then you can assign the Action to any other KeyStroke. The link shows you how to do that in 3-4 lines of code.

  • Can't get Single selection to work in jtable using Netbeans

    I used the GUI editor to create a jTable to play around and I can't get the single selection to work as it should
    I have it set like this:
    jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);The table still selection the rows as if they were set as Multi Interval selection. Anyone could explain why?
    Here is the full source
    To change this template, choose Tools | Templates
    *and open the template in the editor.*
    Tableframe.java
    Created on Jun 7, 2009, 6:57:57 PM
    *package examples;*
    @author ME
    *public class Tableframe extends javax.swing.JFrame {*
    *    /** Creates new form Tableframe */*
    *    public Tableframe() {*
    *        initComponents();*
    *    /** This method is called from within the constructor to
    *initialize the form.*
    WARNING: Do NOT modify this code. The content of this method is
    *always regenerated by the Form Editor.*
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jTable1.setOpaque(false);
            jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jTable1.setShowHorizontalLines(false);
            jTable1.setShowVerticalLines(false);
            jTable1.getTableHeader().setReorderingAllowed(false);
            jScrollPane1.setViewportView(jTable1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(13, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            pack();
        }// </editor-fold>
    *@param args the command line arguments*
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Tableframe().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

    I used the GUI editor to create a jTable to play around and I can't get the single selection to work as it should
    I have it set like this:
    jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);The table still selection the rows as if they were set as Multi Interval selection. Anyone could explain why?
    Here is the full source
    To change this template, choose Tools | Templates
    *and open the template in the editor.*
    Tableframe.java
    Created on Jun 7, 2009, 6:57:57 PM
    *package examples;*
    @author ME
    *public class Tableframe extends javax.swing.JFrame {*
    *    /** Creates new form Tableframe */*
    *    public Tableframe() {*
    *        initComponents();*
    *    /** This method is called from within the constructor to
    *initialize the form.*
    WARNING: Do NOT modify this code. The content of this method is
    *always regenerated by the Form Editor.*
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jTable1.setOpaque(false);
            jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jTable1.setShowHorizontalLines(false);
            jTable1.setShowVerticalLines(false);
            jTable1.getTableHeader().setReorderingAllowed(false);
            jScrollPane1.setViewportView(jTable1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(13, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            pack();
        }// </editor-fold>
    *@param args the command line arguments*
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Tableframe().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

  • JTable with DefaultTableModel not showing?

    I hope this is SSCE...
    I'm using a defaultTableModel, but I cannot get the Table to show.
    When I just simply put the vectors straight into the table, without using the DefaultTableModel it worked.
    This is the code I have now, the table doesn't show at all?
    I actually couldn't get this example to compile, as it only contains snippets of the code. The real code compiles and runs, but the table just doesn't show. I guess it's all part of the same problem.
    If someone could help me with where I've gone wrong in the usage of the DefaultTableModel, it would be greatly appreciated.
    import java.util.Vector;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.TableModel;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.event.*;
    public class FutureTable extends JTable implements TableModelListener {
         Vector colnames = new Vector();
         Vector inne = new Vector();
         TableModel model;
         JTable table = new JTable();
         public FutureTable(){
              //vector colnames
              colnames.addElement("Date");
              //vector inne
              inne.addElement("example")
              //Adds inne and colnames to the TableModel model
              model = new DefaultTableModel(inne, colnames);
              //sets Table to TableModel model
              table.setModel(model);
              //adds a listener to the table
              table.getModel().addTableModelListener(this);
    import javax.swing.*;
    import java.awt.*;
    import java.util.Vector;
    public class FutureTableHolder extends JPanel {
         Vector inne = new Vector();     
         JScrollPane scrollPane;     
         FutureTable theTable = new FutureTable();
         public FutureTableHolder() {          
              //Sets the layout to gridlayout so that the table will fill the panel.
              setLayout(new GridLayout(1,0));
              scrollPane= new JScrollPane(theTable);//ScrollPane
              add(scrollPane);
         }//Ends FutureTableHolder()     
         

    When I just simply put the vectors straight into the table, without using the DefaultTableModel it worked. Well, the code is the same.
    You can use:
    JTable table = new JTable(data, columnNames);or
    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    JTable table = new JTable( model );So you obviously have a problem with your code and you are not building the Vectors the same way. Since you did not post a SSCCE, we can't help (Although as noted above your data Vector is empty so there is no data to display).

Maybe you are looking for

  • Recent CS4 updates disabling pdf creation & Acrobat 9 Pro functioning

    I own Adobe CS4 Suite (Photoshop, Illustrator, InDesign, Acrobat, and shared components).  My computer (Windows Vista) recently installed the latest updates to the software, and ever since, I have not been able to convert any documents to pdf using W

  • How can I sort my imported photo album on the iPhone?

    I would like to sort the imported photos so that the pictures are in the same order as in Photoshop Elements on the PC. Previous to iPhone 4 the sorting was preserved. Now I seem to just have a 'pile' of pictures. Help!

  • Transferring Recorded Movies from MOXIE

    I have cable tv which records and saves wanted programs (MOXIE). It, the converter, needs to be removed, and I want to keep and/or record saved data on my iMac G5. If there is any way to connect them together please let me know. If not, I have an Ext

  • SD Billing - Difficult requirement - 2

    I have a typical requirement where the client works out of a customer location and has a maintenance contract running. For customer work orders against the contract, they book only labour costs while they raise a separate invoice for material based o

  • Save file as date

    import java.io.*; import java.text.*; import java.util.*; public class Test { public static void main(String[] args) throws IOException{ SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyHHmmss"); BufferedWriter writer =new BufferedWriter( new FileW