Disable JTable draggable? // reimporting into a JTable?

How do I disable the ability to drag and drop the colons of a JTable?
I am making a database where I am importing from a file (to view, but not edit it). How can I reimport the file after I have imported it into the JTable?
This is my code at the moment.
    public void reload()
        ArrayList<String> ve = new ArrayList<String>(9); // imports the file into an ArrayList of lines
        try
            BufferedReader reader = new BufferedReader(new FileReader(source));
            String line = null;
            while ((line = reader.readLine()) != null)
                ve.add(line);
            reader.close();
        catch (IOException e)
            System.out.println("Error reading file.");
        ve.trimToSize();
        String [][] data = new String[ve.size()/9][];
        for(int i = 0; i < data.length; i++)
            data[i] = new String[9];
            String name = ve.get(9*i);
            data[0] = name;
String mobile = ve.get(9*i+1);
data[i][1] = mobile;
String dest = ve.get(9*i+2);
data[i][2] = dest;
String tranOut = ve.get(9*i+3);
data[i][3] = tranOut;
String tranIn = ve.get(9*i+4);
data[i][4] = tranIn;
String adult = ve.get(9*i+5);
data[i][5] = adult;
String number = ve.get(9*i+6);
data[i][6] = number;
String dep = ve.get(9*i+7);
data[i][7] = dep;
String arr = ve.get(9*i+8);
data[i][8] = arr;
sort(data); // run quickSort
table = new JTable(data, columnNames);
scrollPane = new JScrollPane(table);
}It works the first time it is run, but not when I try to call it later (from the menus).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

In future, Swing questions should be asked in the [Swing Forum.|http://forums.sun.com/forum.jspa?forumID=57]
The header row of a JTable is really an instance of JTableHeader . Take a look at the API and see if there are any methods that would be of use. (Hint: there are!)

Similar Messages

  • How can I add new row/column into existing jTable?

    Hi add!
    Can you help me how can I add new row/column into existing jTable?
    Tnx in adv!

    e.g
    Create two buttons inside the Table ( "Add New Row" ) and ("Add new Column")
    their handlers are:
    add new row:
    //i supose u already have
    DefaultTabelModel tablemodel = new DefaultTableModel(rowdata, columnNames);
    //and   
       JTabel jtable = new JTable(tablemodel);
    // Handler (row)
    jbtAddRow.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e) {
          if(jtable.getSelectedRow() >= 0 )
              tablemodel.insertRow(jtable.getSelectedRow(), new java.util.Vector());  
           else  
                tablemodel.addRow(new java.util.Vector());
        });to add new columns its the same but inside actionPerformed method:
    ask for e.g "Whats the name for the new column"
    then,
       tablemodel.addColumn(nameOfColumn, new java.util.Vector());   Joao
    Message was edited by:
    Java__Estudante

  • Loading the Contents of a file into a JTable

    I am trying to load the content of a delimited (tab, comma, etc), into a JTable. The code is very simple and works for the most part. Here is some of it:
                   List tableRows = new ArrayList();
                   String lineItem = "";
                   InputStream in = new FileInputStream(fName);
                   InputStreamReader isr = new InputStreamReader(in);               
              BufferedReader br = new BufferedReader(isr);
         while((lineItem = br.readLine()) != null)
                        if(x == MAX)
                             break;
                        java.util.List rowData = new ArrayList();
                        StringTokenizer st = new StringTokenizer(lineItem, "\t");
                        while(st.hasMoreElements())
                             rowData.add(st.nextToken());
                        tableRows.add(rowData);     
                        x++;
    Basically, tableRows, ends up to be a List of Lists which I later use to populate the Object[][] for the JTable rows. This works perfect!
    My problem has to do with the tokenizer. In some situations, values in a line that is read contains "". For example an line read (quotes are showed only to distinquish values in the line):
    "item1", "item2", " ", "item4", " ", "item6", "item7"
    The tokenizer does not capture the " ". So instead of 7 tokens, it only sees 5.
    My question is, can someone tell me a better approach for tokenizing the string so that it captures everything?
    Thanks in advance,
    Augustine

    I am trying to load the content of a delimited (tab, comma, etc), into a JTable. The code is very simple and works for the most part. Here is some of it:
                   List tableRows = new ArrayList();
                   String lineItem = "";
                   InputStream in = new FileInputStream(fName);
                   InputStreamReader isr = new InputStreamReader(in);               
              BufferedReader br = new BufferedReader(isr);
         while((lineItem = br.readLine()) != null)
                        if(x == MAX)
                             break;
                        java.util.List rowData = new ArrayList();
                        StringTokenizer st = new StringTokenizer(lineItem, "\t");
                        while(st.hasMoreElements())
                             rowData.add(st.nextToken());
                        tableRows.add(rowData);     
                        x++;
    Basically, tableRows, ends up to be a List of Lists which I later use to populate the Object[][] for the JTable rows. This works perfect!
    My problem has to do with the tokenizer. In some situations, values in a line that is read contains "". For example an line read (quotes are showed only to distinquish values in the line):
    "item1", "item2", " ", "item4", " ", "item6", "item7"
    The tokenizer does not capture the " ". So instead of 7 tokens, it only sees 5.
    My question is, can someone tell me a better approach for tokenizing the string so that it captures everything?
    Thanks in advance,
    Augustine

  • Inserting values from sql into a JTable

    Good day all,
    Please I need someone's assistance as regard inserting data retrieved from JavaDB into a JTable I created in NetBeanns6.5.
    I have to click on a ViewData Button in order to display data in the JTable below.
    Please I need a simple example to demostrate it.
    Also, how can I resize the column of my JTable so that I can see fully what is retrieved from the database, cos I have one that retrieves but the column is not wide enuogh to accommodate the data.(I did this outside NetBeans)
    Thanks
    Alam Ikenna Winner.

    First, learn to use PreparedStatements. Then we can talk further.

  • Moving a ResultSet into a JTable, cheaply and efficiently.

    Hi,
    This may be something interesting for the more advanced Java programmers.
    I've recently run into an issue, with moving a ResultSet into a JTable. Now, this may seem simple, and believe me it is, but, all the ways I have seen it done, and tried, just don't suite my need.
    DBSql dbsql = new DBSql(); // My database handler class
    tableResults.setModel(new javax.swing.table.DefaultTableModel(dbsql.execute(script), dbsql.getColumns()));
    * Queries the DataBase and populates
    * the values into a two-dimensional object array
    * @param SqlQry
    * @return Object[][]
    public Object[][] execute(String SqlQry) throws SQLException {
    Object[][] obj = null;
    select = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = select.executeQuery(SqlQry);
    rsmd = rs.getMetaData();
    try {
    if (rs.next()) {
    boolean found = true;
    rs.last();
    recordCount = rs.getRow();
    rs.first();
    obj = new Object[recordCount][rsmd.getColumnCount()];
    int i = 0;
    while (found) {
    for (int j = 0; j < rsmd.getColumnCount(); j++) {
    obj[i][j] = rsmd.getColumnType(j + 1) != Constants.TYPE_INTEGER ? rs.getString(j + 1) : rs.getInt(j + 1);
    i++;
    found = rs.next();
    } else {
    recordCount = 0;
    return null;
    } catch(OutOfMemoryError oome) {
    System.gc();
    throw new SQLException("Out Of Memory");
    if(rs != null) rs.close();
    return obj;
    The application I have created is used to connect to any database I want. I have tested it with JavaDB, Microsoft Access, and DB2. The problem is, most DB2's have tables with many records and columns, while most new Relational Databases, have small tables with few records. This code works fantastic with a couple thousand records, with very few columns. But, doesn't cut it when it comes to 50000 records or more. For, instance I queried a DB2 table that has 34000 records and 117 columns ("select * from table"), it doesn't take too long, but it uses way too much memory. If I run that query the application resources 298mb, then when I run it again, it uses a little more and throws an OutOfMemoryError.
    The second issue I have is, I queried another table that has 147000 records and selected 4 columns. No OutOfMemoryError this time - 70mb resourcing - but, the application did take at least 20 minutes to collect those records.
    I have tried using the Vector<Vector<String>> type into the JTable, but, frankly that's just asking for an OutOfMemoryError.
    I have tried creating my own custom table model, with a created data object.
    I have tried inserting rows into a table model in the method itself and returning the table model.
    Eg.
    while (found) {
    Object[] obj = new Object[rsmd.getColumnCount()];
    for (int j = 0; j < rsmd.getColumnCount(); j++) {
    obj[j] = rsmd.getColumnType(j + 1) != Constants.TYPE_INTEGER ? rs.getString(j + 1) : rs.getInt(j + 1);
    tablemodel.insertRow(obj);
    found = rs.next();
    ^I think you can use a vector for this too.
    So far, nothing has solved my problem.
    One thing I have not tried however, is a different table component for this kind of thing.
    I'm basically looking for, a method of doing this, with less overhead and quicker table population.
    Any Ideas?
    Regards,
    That_Gui

    Thanks for the reply.
    "1) Swing related questions should be posted in the Swing forum."
    Apologies, I was caught between swing and essentials, as it seemed to me as, more of a "better ways to do things" kind of question.
    "Also, the approach you are using requires two copies of the data, one in the ResultSet and one in the TableModel."
    I understand that transferring a ResultSet into an Object Array may probably be resource intensive, my delphi colleague made mention of that to me, not too long ago. That is why I'm trying to transfer the ResultSet directly into the table. That is why I used the ListTableModel, which also uses a lot of memory, I have looked at that - I had forgotten to mention that.
    "I have seen approaches where you try to only read a specific number of records. Then as you scroll additional records are read as needed. I can't point you to any specific solution though."
    Using an approach of reading the data as you scroll, sounds great, but also sounds like unnecessary work for the program to do, just like this Object/Vector story. In RPG, if you are working with subfiles (like a JTable), you will display 10 records at a time, and if the user hits the Page Down button you will display the next 10, that is how I'm understanding it.
    "I rarely use DefaultTableModel, creating your own model from AbstractTableModel is a lot more flexible when it comes to how you organise your storage, and it's pretty simple once you get the hang of it."
    This is the dream, I just need to design one that works as I need it.
    "You'd do a select count(*) on your query first to get the total rows expected. Of course one of the problems is that the databased table may change after you've retrieved the length or the items."
    Unfortunately, this is not an option for me, it wont work for what I need.
    I'm going to give the ResultSetTableModel a go - which I think it is actually similar to the ListTableModel - and I will get back to you.

  • JButtons into a JTable

    Is it possible for me to get a JButton into and JTable? The Table contents come from the code below.
    server myserver= new server();//make object of this class
    network mynetwork= new network(myserver);// make network objectand pass server as refrence
    int row,col;
              //initialise string database for hosts
              for (row=0;row<50;row++){               
                   myserver.hostdb[row][0]=""+iconButtons;
                   for (col=1;col<8;col++){
                   myserver.hostdb[row][col]="";
    Any help would be appriciated thanks.

    Yes
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender

  • How to insert rows & columns into a jTable???

    helloo there...
    How to insert rows & columns into a jtable???
    your reply is greatly appreciated....
    -=samer=-

    Yes!thanks...
    But what i want is how to set the number of rows and the number of columns...and i don't know how to setColumns and rows....any idea?
    the user will input number of rows and columns in a jtextfield....
    Please rply...

  • Enable Dropping into Empty JTables

    Hi there!
    I've just posted another blog on Swing Drag and Drop. Learn how to enable dropping into empty JTables with a single method call in Mustang, or a simple override in earlier versions of J2SE.
    http://weblogs.java.net/blog/shan_man/archive/2006/01/enable_dropping.html
    All the best,
    Shannon Hickey (Swing Team)

    Hi,
    It looks like below bug in SQLDeveloper.
    Bug 6326721: Updatable views - could not insert, update and delete as for tables.
    Please close the thread, if I answered your question.
    Regards,
    Satishbabu Gunukula
    http://oracleracexpert.blogspot.com

  • Pass a xml file into a JTable

    I'm new to java and xml, I need to pass a xml file into a JTable.
    thanks

    That error about the package not existing probably means that your classpath is wrong. Is JDOM in a Jar file? If so, add it to the classpath on the command line:
    javac -classpath C:\JDOMPath\JDOM.jar;C:\MyClasses DescendantDemo.java(put whatever directories and jar files you need in the classpath).

  • How to select rows in the inner JTable rendered in an outer JTable cell

    I have wrriten the following code for creating cell specific renderer - JTable rendered in a cell of a JTable.
    table=new JTable(data,columnNames)
    public TableCellRenderer getCellRenderer(int row, int column)
    if ((row == 0) && (column == 0))
    return new ColorRenderer();
    else if((row == 1) && (column == 0))
    return new ColorRenderer1();
    else
    return super.getCellRenderer(row, column);
    ColorRenderer and ColorRenderer1 are two inner classes, which implement TableCellRenderer to draw inner JTable on the outer JTable cell, having 2 rows and 1 column each.
    Now what is happening the above code keeps executing continously, that is the classes are being initialised continously, inner JTables are rendered (drawn) continously, and this makes the application slow after some time. It throws java.lang.OutOfMemoryException.
    WHY IS IT SO??? I can't understand where's the bug..
    Any advice please???
    Moreover i want selections in inner tables and not on outer table, how can this be possible.
    I am working on this since a long time but have not yet found a way out...

    With your help i have overcome the problem of continous repeatition.
    The major problem which I am facing is, in selecting rows in the inner rendered JTables.
    I have added listener on outer JTable which select rows on the outer JTable, hence the complete inner JTable which being treated as a row, gets selected.
    The thing is i need to select the rows of inner rendered JTables,not the outer JTable.
    How to go about it??
    I have even added listener to inner rendered JTables, but only first row of every table gets selected.
    Please help....
    Thanks in advance.

  • If exporting images for backup, to reimport into a clean aperture or other program, is it best to use 72 dpi or 300 dpi, or does it matter?

    If exporting images for backup, to reimport into a clean aperture or other program, is it better to use 72 dpi or 300 dpi, or does it matter?  I want the best quality for any future unforeseen use. 

    I am somewhat reluctant to answer your questions after Frank Caggiano's excellent advice, but I really do not like to leave the question open, for there will be many occasions when you will need to export images and to understand how it works.
    But please, follow Frank's advice, right now you do not need to worry about pixels and dpi. That is exactly what I meant, when I suggested to you to make sure you keep a copy of your Aperture Library and to back it up with all your other data, before you erase your disk for a clean reinstall.
    DPI revisited:
    So, is the dpi setting only for exporting to print?
    The dpi settings are necessary to define the size of a digital image, since pixels don't have any dimensions. And since you cannot print or display an image without knowing its width and height, you will need to specify dpi when you are printing or scanning.
    If I leave it at the default 72dpi will there be any problems getting quality prints in the future from jpeg versions exported with that setting?
    Not if you export with the original size - the maximum number of pixels available. That will ensure the maximum print quality.
    The dpi settings are required to export versions; versions are derived from the masters and new image files are computed. When you export masters you get a copy of the original file that already may have a dpi setting.
    If I choose "export masters", will aperture will export my masters just as they are? 
    yes, and  you may add IPICT data if you choose
    Pardon my thick skull--I'm an old dog trying to learn new tricks in this digital world!
    No apologies necessary, we were all beginners once
    Here is another example, maybe that helps a little:
    I exported an image (jpeg) with three different setting: export masters, a version with 72dpi, a version with 300dpi and inspected the files in Graphic Converter:
    The master was exported like this:
    Notice, the master had already dpi settings, although I did not specify any on export.
    The size is 51,48 cm x 38,61 cm.
    The 72 dpi Version has larger dimensions, but also 10 Megapixels.
    and here the 300 dpi version: smaller dimensions, same amount of pixels.

  • Why are the videos sent from my daughter's iPhone 4 to my 4S in 3gp format? i need to drag to desktop - open with QuickTime - convert - reimport into iPhoto.

    why are the videos sent from my daughter's iPhone 4 to my 4S in 3gp format? i need to drag to desktop - open with QuickTime - convert - reimport into iPhoto. There must be another way.  Plus

    Hey joshuafromisr,
    If you resintall iTunes, it should fix the issue. The following document will go over how to remove iTunes fully and then reinstall. Depending on what version of Windows you're running you'll either follow the directions here:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP
    http://support.apple.com/kb/HT1925
    or here:
    Removing and reinstalling iTunes, QuickTime, and other software components for Windows Vista or Windows 7
    http://support.apple.com/kb/HT1923
    Best,
    David

  • Trying to import from different csv files into multiple JTables

    This might seem like something that isn't commonly done, but I'll see if anyone has done this before anyways.
    I currently have a JTable (tab #1) and it successfully reads in the data from a CSV file to populate the cells. Now, I am looking into making 3 more JTables. I can tab between the four different tables, but I can't seem to figure out how to get the data to go to the correct JTable. Tab #1 = table, Tab #2 = table2, Tab #3 = table3, Tab #4 = table4.
    Thanks.
            try
                FileInputStream fileInput = new FileInputStream ("upcoming.csv");
                BufferedReader InputCSV = new BufferedReader (new InputStreamReader (fileInput));
                line = InputCSV.readLine(); //start reading into the records.
                    //Create data for the table.
                    //the row variable = starting row
                int row = 0;
                while(line != null)
                    tmp = line.split(",");
                    for (int col = 0; col < columnNames.length; ++col)
                        data[row][col] = tmp[col]; //store cells' data to the 2-dimensional array.
                    row++;
                    line = InputCSV.readLine();
                }//end of WHILE-statement.
            } //END of TRY-statement.
            catch(Exception e)
                System.out.println(e);
            }

    I have been successful in my quest to get 4 different datasets into 4 different JTables. The previous posters suggestion to use the Table model led me to this page:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/table/TableModel.html
            TableModel myData = new MyTableModel();
            JTable table = new JTable(myData);I had some very similar code in my program. I use the DefaultTableModel and the SortFilterModel before having 4 different JTables.
            DefaultTableModel model = new DefaultTableModel(data, columnNames);
            DefaultTableModel model2 = new DefaultTableModel(data2, columnNames);
            DefaultTableModel model3 = new DefaultTableModel(data3, columnNames);
            DefaultTableModel model4 = new DefaultTableModel(data4, columnNames);I use the code in the first post 4 times, and only change the filename and the data#.
    I also have some code that counts the number of lines that will be needed.
    Thanks.

  • How to disable a particular row in a JTable

    How can a disable only a particular row/column in a JTable.
    I am trying to create an XML Notepad type of application for which I need the row which contains the root element or any element which has a child element to be disabled. How can I achieve this??
    I would be grateful for replies.

    Hi,
    Create your own class which extends TableModel and in that class u override the method
    public boolean isCellEditable( int row, int col)
    As u know the row and col which u want to disable hard code those values in the method.
    Like
    public boolean isCellEditable( int row, int col)
    if( row == 2 and col == 1 )
    return false
    else
    return true
    Hopefully this provides u with a solution.
    Cheers :)
    Nagaraj

  • WRAP JTable Column Name into 2 lines

    I have a JTable with a long column Name. Can I wrap the Column Name into multiple (2) lines.

    baskaraninfo wrote:> set the following to a table column,<html><body>Employee<br>Name</body></html>>The break tag got lost cos you didnt use the code tags
    <html><body>Employee<br>Name</body></html>

Maybe you are looking for

  • Follow-up transaction copy control for opportunities

    Our CRM system is currently configured to permit follow-up opportunity creation.  When follow-up transactions are created all product categories are copied to the new opportunity.  We would like to stop this.  All header and business partner data sho

  • How to use apps store in 2g  can t download

    hi  i have iphone 2 g 3.1.3 cant downloade apps so plz tell me cydia is not working in my  iphone

  • 11.2.0.2 to 11.2.0.3

    Version: 11.2 Platform : Solaris x86 (64-Bit) I want to upgrade my 11.2.0.2.0 DB to 11.2.0.3.0. I realise that , starting from Sep 2010 release of 11.2.0.2, patchset comes in a single Installable. This is very usefuly when we do fresh Installation. B

  • Restored from backup - trouble authorizing some items

    I had to restore from a backup. It now won't authorize about 100 items to be played or synced with my iPod. It is asking me for my old Apple ID that I changed when I got my mac as I then had a .mac account to use. What can I do to get all those purch

  • Could not find Main Class while running JAR   outside /dist directory

    Hello I can make jar on netbeans by clicking Shift+F11. But the problem occurs when I copy paste my jar file out of /dist directory. It only works at /dist directory. I think my way making jar is incorrect. Anyone knows a way to make runnable jar by