JTable Doubt...

How to remove a row from JTable
Ranjith.M

Hi,
DefaultTableModel dtm = (DefaultTableModel)table.getModel();
dtm.removeRow( 2 );
Regards,
Manfred.

Similar Messages

  • JTable Column Max Number Doubt

    Hello there,
    I have this JTable Doubt. I have always been strugling with jtables and here I am stuck again and not able to do this.
    My Database has defined a column that accepts a String Number. It can have upto 4 decimals and 2 fractional Numbers. So thats a total of 6 digits with a contraint as mentioned above.
    I can have user input as 9999.99 and not 99999.9
    Could you please tell me how I could have one of my JTables column to accept only input like this.
    Regards,
    Hemanth

    It is not clear to me whether you are talking about rendering or editing.

  • Maximum Allowed Text Length for JTable Column

    Can you please help me with a JTable Doubt
    How do I set the Maximum Allowed Text Length for a Particular Column of a JTable?

    Thanks a lot mate. I used the following
         class MaximumLengthFilter extends DocumentFilter {
                   public void replace(DocumentFilter.FilterBypass fb, int offset, int length,
                             String text, AttributeSet attr) throws BadLocationException {
                        if ((fb.getDocument().getLength() + length) < 10)
                             fb.replace(offset, length, text, attr);
                        else
                             Toolkit.getDefaultToolkit().beep();
              }

  • JTable Redering doubt

    When we create DefaultTableCellRenderer and use it for JTalbe using command
    table.setDefaultRenderer( Class.forName( "java.lang.String" ), renderer );
    what is the first argument for ???

    I want to change teh background of table based on an array . Even though it shows the table the method defined below is not called......
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.table.*;
    class MyCellRenderer extends DefaultTableCellRenderer {
         double []bidView;
           public MyCellRenderer(double bidView[]) {
        this.bidView=bidView;
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
         System.out.println("HERE");
           super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
           if (!(value instanceof String))
                return this;
        String stringValue = (String)value;
        try {
              if ( bidView[row]==1)
                  setBackground( Color.RED );
             else
                  setBackground( new Color(252,0,0) );
        } catch ( Exception e ) {}
      return this;
    public class ResultGUI extends JFrame
         Result result;
         int height,width;
         JPanel bidViewPane,itemViewPane,infoPane;
         JList bidJList,itemJList;
         JScrollPane jscPane[];
         Container cpane;
         public ResultGUI(BidGenerator bg,String filepath)
               try{
                   //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                  } catch(Exception e){}
              result= new Result(bg,filepath);
              initGUI();
         private JTable getBidViewTable(Vector bidList)
              String temp;
              int i,bidcount=bidList.size();
              Object bidView[][]=new Object[bidcount][3];
              for(i=0;i<bidcount;i++)
                        bidView[0]=new String(i+"");
                        temp=(String)bidList.get(i);
                        StringTokenizer stoken=new StringTokenizer(temp,";");
                        bidView[i][1]=stoken.nextToken();
                        bidView[i][2]=stoken.nextToken();
              String[] columns={"Serial No.","Items Bidded","Price Quoted"};
              JTable table=new JTable(bidView,columns);          
              return table;
         private JTable getItemViewTable(Vector itemViewVector)
              int i,itemcount=itemViewVector.size();
              Object itemView[][]=new Object[itemcount][2];
              for(i=0;i<itemcount;i++)
                   itemView[i][0]=new String((1+i)+"");
                   itemView[i][1]=itemViewVector.get(i).toString();
              String[] columns={"Item Serial No.","Won By"};
              JTable table=new JTable(itemView,columns);          
              return table;
         public void initGUI()
              double resultArray[]=result.getResultList();
              Vector bidList =result.getBidList();
              Vector itemview          =result.getItemwiseVector();
              String temp="";
              setBounds(0,0,800,600);
              cpane=getContentPane();
              setBounds(0,0,800,600);
              cpane.setLayout(new GridLayout(3,1));
              JTable table=getBidViewTable(bidList);
              TableCellRenderer renderer = new MyCellRenderer(resultArray);
              try
    table.setDefaultRenderer( Class.forName( "java.lang.Integer" ), renderer );
    //table.setDefaultRenderer(null, renderer );
    catch( ClassNotFoundException ex )
    ex.printStackTrace();
              JScrollPane scrollPane = new JScrollPane(table);
              scrollPane.setBounds(0,0,getWidth(),getHeight()/2);
              cpane.add(scrollPane);
              setTitle("Combinatorial Auction");
              setVisible(true);

  • Jtable focus doubt

    Hi all,
    I have been searching for awhile now and could not find what I was looking for.....
    I have a Jtable where the user inserts some numbers and then presses a button.
    I need to remove the focus from the table so that I can insert the data correctly into the DB.
    I tried
    table.setFocusable(false);and also
    table.setEnabled(false);does anyone know a sollution for this?
    thanks in advance!

    right.........
    I just realised that my problem is not related to focus.....
    the user double clicks on the cell he wants to edit....
    and when he presses the button, the cursor (or whatever it's called ) remains in the cell, and because of that, the value is not inserted....

  • Doubt JTable

    Hello everybody, I have a JTable and I need that for example when the user clicks right in a row a menu until I got there, now I want to when they click on the name of the column to the right appeared another menu with options regarding the selected column.
    How do I do this??

    vmsb11 wrote:
    Hello everybody, I have a JTable and I need that for example when the user clicks right in a row a menu until I got there, now I want to when they click on the name of the column to the right appeared another menu with options regarding the selected column.
    How do I do this??Post an [SSCCE |http://sscce.org] demonstrating where you got stuck, and we'll go from there. Otherwise, just read the tutorials on menus and MouseListeners.

  • How do I change the colour of a selected cell in a jTable?

    I have a Jtable that displays URL names in one column. There are several problems I'm having. The effect I'm trying to achieve is this:
    When the user runs the mouse over the URL name the cursor should change into a hand (similar to what happens in an HTML hyperlink). I'm aware that the Cursor class can set the cursor graphic so i figure that i need a listener of some sort on each cell (so the cursor can change from an arrow to a hand) and also one to indicate when the cursor is not on a cell (so that it can change from a hand back into an arrow). Is this the right track?
    Also, I've looked at the DefaultTableCellRenderer class (which, as i understand it, is responsible for how each cell in the jtable is displayed) for a method that will allow me to set the background of a selected cell (or row or column). I require this because each time i select a cell (or row) it becomes highlighted in blue. I would rather it just remained white and changed the cursor to a hand. I know there exists a method for setting the background for an unselected cell but none for a selected cell. Again, I'm not sure if I'm going down the right track with this approach.
    Lastly, if the cell has been selected (by a mouse click) the font of the writing in the cell (i.e. The name of the URL) should change. This shouldn't be too much of a problem I think.
    I do not expect anyone to provide code to do all of this but some general pointers would be extremely helpful as I do not know if I'm thinking on the right track for any of this. Having some (limited) experience with Swing I doubt there is a simple way to do this but I can only hope!
    Thanks.
    Chris

    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    there you can find some examples with CellRenderer's and so on ...
    have fun

  • How to create Hyperlink column in a JTable

    Can anyone help in creating a hyperlink column in a JTable.
    Thanks in advance,
    Sridhar.

    If the parent is an Applet it is very simple .
    catch the mouse click on columns and execute the following code
    String url = getValueAt(i,j);
    getAppletContext().showDocument(new
    URL(url ), "_blank");
    thatz all .
    if ur program is an application use this getRuntime.exec() and use parameters to rundll32.exe url and iexplore.exe in Windows platform,
    if u have still doubts plz get back to me
    Renjith K.V

  • Who's been f**king with my JTables

    OK....own up....who's broken all my JTables!?!?
    I went on holiday 2 months ago (i know....nice holiday!) and have returned this morning to find that my editable JTables no longer work correctly.
    If i edit a cell and then click on another component, the edit no longer gets committed automatically in the way it did before i left. Needless to say, I am not amused. I've found a solution to the problem by setting the value of the "terminateEditOnFocusLost" property on my JTables but i really can't understand what's happened in the previous 60 days to make this suddenly necessary. A swift look at our CVS logs appears to confirm my work colleague's innocence, although they're fiendishly cunning in their incompetence at times!
    If anyone has any ideas who has brought this befuddlement upon me i'd be exceedingly grateful to know. Prime suspects are currently the good people of Sun!! Defend yourselves if you dare!!
    Cheers,
    Dave

    the edit no longer gets committed automatically in the way it did before i leftThe edit never did get committed automatically when the table lost focus, only when you click/move to another cell in the table.
    The "terminateEditOnFocusLost" property was added in 1.4 as a table property because you can't change the default behavour from one release to the next.
    So I doubt your code worked correctly before you went on holidays.

  • Dinamic TableModel with JTable

    Hi,
    I have a JTable table = new JTable(); with a default table model when my JDialog starts.
    But, when the user types two informations (number of lines/columns) and press a button "Generate table", I'd like to generate a new model with these lines/cols.
    But when I run this code in "Generate table", none occurs:
        for (i = 0; i < rows.size(); i++)
          dataModel.setrow((ArrayList) rows.get(i));
        table.setModel(dataModel);If I put this code when generating the table at JDialog constructor, all works fine.
    Then, my doubt is: is not it possible to use a new data model dinamically?

    After setting the model to the table calldataModel.fireTableDataChanged();

  • Behavior of ENTER arbitrarily changes in my JTable

    The setup: basic, non-exotic JTable in a 1.6.0_02 application running on Red Hat Enterprise 3.
    Normal behavior: hitting enter causes the table to select the next cell row.
    My behavior: randomly, I've been noticing that hitting enter causes the cell to start editing! Once in this state, the original behavior can't be restored without restarting the application. I can't figure out what causes this behavior to start. It only happens a small percentage of the time.
    Any idea what the deal is here? It seems doubtful that the input map for the table could get whacked. The table still responds as you'd expect to other mouse and key events. Again, I don't have any fancy editors or anything... just some basic text type editors that extend the default. None of them do anything funky with key events.
    Unfortunately this issue was noticed in production and it is bugging the users who do a lot of data entry. So I'm very grateful for any suggestions.

    Good thought, I checked this out just to make sure. My table's data is in fact updated upon receipt of network messages, however, all the work is done through an invokeLater() and thus happens on the ED thread.
    Without seeing the code and a process to reproduce the problem, I know I'm not going to get an exact answer, but if anyone else has any ideas of potential causes or places to look, I'm all ears.

  • How to use setDragEnabled in a JTable with Textbox

    Hi all,
    I am new to swings and have a very urgent doubt.I want to select and drag the row of the JTable and place it in the text box.How do I do it.An Example program will solve my query.Please Its Very urgent.
    thanks in advance
    With kind Regards
    Satheesh.K

    Hey Lynx,
    The 'you are running this application for the first time' thing is normal as most applications will put a few plist files and settings in a couple of places in your home /library folders. I wonder though about having to re-serialize...Have you installed them in other places rather than your /Applications folder? If not, some applications will ask if you want to install for all users or not- but I'd say that user speciffic applications are about 20-30% of apps...-ish ^^
    Maybe running the installers and installing for allusers would save you a bit of a hassle going forward?
    hope it helps

  • JTable - row focus color

    I wrote a program which will change the color of each row.
    odd row background color will be white
    even row background color will be gray.
    My doubt is?
    if i move the mouse on the any row, that row should have a different background color (dark of row background)

    I tried with DefaultTableCellRenderer, but it is not
    workingIs this what you want?
    import java.awt.Color;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    public class RowColor extends JFrame {
        public RowColor() {
            Object[][] data =
                {"Row 1", "Row 1"},
                {"Row 2", "Row 2"},
                {"Row 3", "Row 3"},
                {"Row 4", "Row 4"}
            Object[] columnNames = {"Column 1","Column 2"};
            JTable table = new JTable(data, columnNames) {
                public TableCellRenderer getCellRenderer(int row, int column){
                    DefaultTableCellRenderer c = (DefaultTableCellRenderer)super.getCellRenderer(row, column);
                    if (row % 2 == 0)
                        c.setBackground(Color.GREEN);
                    else
                        c.setBackground(Color.YELLOW);
                    return c;
            JScrollPane scrollPane = new JScrollPane( table );
            getContentPane().add( scrollPane );
        public static void main(String[] args) {
            RowColor frame = new RowColor();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

  • JTable without JScrollPane behavior crippled

    I want column width of JTable t1 goes parallel with the width resizing on
    JTable t2. If tables are put in JScrollPanes, this has no problem. But if I put
    those tables in simpler container, which is JPanel in this case, t2 shows a
    funny behavior -- with user's mouse operation on t2 column, their width
    never changes but t1 column width changes properly. Could I have
    succeeded in communicating the funniness with these sentences?
    Please try this code and give cause and solution if you could:
    import java.awt.*;
    import java.beans.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    public class TableColumnWidthResize{
      JFrame frame;
      JTable t1, t2;
      TableColumnModel tcm1, tcm2;
      Enumeration columns1, columns2;
      String[] t1h = {"Road", "Length", "City"};
      String[][] t1c
       = {{"NW2", "800", "Dora"},
         {"Iban", "600", "Weiho"},
         {"ENE2", "500","Porso"}};
      String[] t2h = {"Flower", "Curse", "Priest"};
      String[][] t2c
        = {{"Fang", "7.00", "EggChar"},
          {"Shaoma", "5.00", "ScaCra"},
          {"Jiao", "4.00", "PorCabb"}};
      public TableColumnWidthResize(){
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container con = frame.getContentPane();
        con.setLayout(new GridLayout(2, 1));
        t1 = new JTable(t1c, t1h); //target table -- 'resized from t2'
        t2 = new JTable(t2c, t2h); //source table -- 'initiate resize'
        t1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        t2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        /* you can compare two methods of table placement*/
        useScrollPane(t1, t2, con); //works fine
    //    nouseScrollPane(t1, t2, con); //resize behavior weird
        frame.pack();
        frame.setVisible(true);
        tcm1 = t1.getColumnModel();
        tcm2 = t2.getColumnModel();
        columns2 = tcm2.getColumns(); // all columns of t2
        TableColumnListener tcl = new TableColumnListener();
        while (columns2.hasMoreElements()){
          TableColumn tc = (TableColumn)(columns2.nextElement());
          tc.addPropertyChangeListener(tcl);
      class TableColumnListener implements PropertyChangeListener{
        // achieve 'interlocking-column-resizing' from t2 to t1
        public void propertyChange(PropertyChangeEvent pce){
          TableColumn tc = (TableColumn)(pce.getSource());
          int i = tc.getModelIndex();
          tcm1.getColumn(i).setPreferredWidth(tc.getWidth());
      void useScrollPane(JTable ta, JTable tb, Container c){
        JScrollPane jsc1 = new JScrollPane(ta);
        ta.setPreferredScrollableViewportSize(new Dimension(225, 50));
        JScrollPane jsc2 = new JScrollPane(tb);
        tb.setPreferredScrollableViewportSize(new Dimension(225, 50));
        c.add(jsc1); c.add(jsc2);
      void nouseScrollPane(JTable ta, JTable tb, Container c){
        JPanel p1 = new JPanel(); JPanel p2 = new JPanel();
        p1.setLayout(new BorderLayout());
        p2.setLayout(new BorderLayout());
        p1.add(ta.getTableHeader(), BorderLayout.PAGE_START);
        p2.add(tb.getTableHeader(), BorderLayout.PAGE_START);
        p1.add(ta, BorderLayout.CENTER);
        p2.add(tb, BorderLayout.CENTER);   
        c.add(p1); c.add(p2);
      public static void main(String[] args){
        new TableColumnWidthResize();
    }

    Hey hiwa,
    I don't see anything mysterious going on. If you think about it, how many components can we resize at run-time/dynamically with a mouse - none, except for the columns in a JTable, Frames and Dialogs. Note the latter two are top level and answer to no-one (except the screen i guess).
    If you have ever implemented a component that can be 'dragged' and manipulated by the mouse, have you ever done so outside, that is, not using a JScrollPane? I doubt it.
    I do not think it has anything to do with mouse precision. Maybe you are just experiencing undefined behaviour, unreliable behaviour. I imagine the Swing team didn't bother themselves with a usage scenario that would yield lesser results for a simple task. Using AUTO_RESIZE_OFF and requesting more room than the Container has to offer may upset that containers LayoutManager i.e. their algorithms may contain code that will shrink child components to fit, or nab space from sibling components.
    Basically, in my experience, how ever long it takes me to realise it, when Swing goes on the blink it is usually a programming error.
    BTW, did my suggestion work ok?
    Sorry if I come across forceful. I'm glad I read and tested your code - the synchronization effect will be very useful.
    Warm regards,
    Darren

  • Convert HTML table to JTable

    do you have any way to convert HTML table ( in HTML file) to JTable?
    Thanks in advance.

    Not that I'm aware, and I doubt you'll find built-in support for it any time soon. HTML "tables" and Java "tables" are two very different things. HTML table data is inlined whereas JTables are strictly an MVC design. HTML table data is static whereas JTable data needn't be; the same can be said for the layout, column widths, and column positions.
    It would not be impossible to create a simple parser which read a basic HTML table element and generated a JTable/TableModel based on that information; the amount of work involved would be affected, of course, by the number of HTML table features you'd want to support.
    What precisely motivates you to do this? Are you trying to create a Java web browser?

Maybe you are looking for

  • Oracle Forms 6i(32-bit)  = Oracle database 10g R2 Windows 2008 R2 64-bit)

    We have Oracle database 10g R2 installed on a Microsoft Windows 2008 R2 (64-bit) (SERVER1) We have Oracle Forms 6i (patch 4a) installed on a Microsoft Windows XP Professional (32-bit) (SERVER2) I am not able to connect from SERVER2 to SERVER1, either

  • Photoshop Error - Exception Type:  EXC_BAD_ACCESS (SIGBUS)

    Everytime I open files in Photoshop (even after installing the correct fonts), Photoshop crashes. Help! Process:         Adobe Photoshop CS5 [4308] Path:            /Applications/Adobe Photoshop CS5/Adobe Photoshop CS5.app/Contents/MacOS/Adobe Photos

  • PDF files in preview crash computer after installing Yosemite

    I recently upgraded to Yosemite on my macbook pro. Being a student I often have a few PDF files (research articles) open at once during class or when working. My macbook never crashed before but now as I am scrolling through the articles or using the

  • Collecting Message based on Delivery Id

    Hi, We have an scenario to collect the messages based on delviery number, like customer sends the bulk order and SAP splits that order and create the delivery for each splitted orders . Eg. Sales Order     Batch Order PO#      1234 This Batch order i

  • Personality development plan customization

    Hi All, Good Morning. I am new into OA framework.Here i got requirement Personality development plan customization in r12 version. Navigation: Performance Management > Competence Appraisal Plan / Self Assessment > Appraisals Action Button > Final Rat