Moving row in Jtable

Hi,
what i want is to move row UP and DOWN. I have my own Abstract table model. Im looking for the easyest way to do this.
public void moveRow(int i, int j){
    Vector v = new Vector();
    v = (Vector)data.get(j);
    data.add(j, data.get(i));
    data.add(i, v);
    fireTableRowsUpdated(i,j);
  }

The following example moves the selected row of a table up or down
    m_table - your JTable
    m_model - your DefaultTableModel
    m_btnUp, m_btnDown  - your up/down buttons
    m_btnUp    .addActionListener(new MoveUpAction());
    m_btnDown  .addActionListener(new MoveDownAction());
    class MoveUpAction implements ActionListener
        public void actionPerformed(ActionEvent e)
            int row = m_table.getSelectedRow();
            if (row == -1) return;
            if (row ==  0) return;
            m_model.moveRow(row,row,row-1);
            m_table.setRowSelectionInterval(row-1, row-1);
    class MoveDownAction implements ActionListener
        public void actionPerformed(ActionEvent e)
            int row = m_table.getSelectedRow();
            if (row == -1) return;
            if (row ==  m_table.getRowCount()-1) return;
            m_model.moveRow(row,row,row+1);
            m_table.setRowSelectionInterval(row+1, row+1);
    it will be wise to set the table to have single selection:
         m_table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

Similar Messages

  • DragnDrop row in JTable

    I need to add dragndrop functionality to my JTable. I am using AbstractTableModel since I need to control the data at runtime.
    Can anyone give sample code to insert row.

    Drag and Drop not working for me.
    My table model is
    public class ExportEditTableModel extends AbstractTableModel {
         String[] columnNames = null;
         Object[][] rowData = null;
         JTable table = null;
           Object[][] data = null;
           Object prior_value = null;
              int changed_row ;
          int changed_col ;
          Object changedValue;
          Vector dataVector;
          int modCount = 0;
          int elementCount;
          Object elementData[];
         public ExportEditTableModel()
         public void setColumnNames(String[] columnNames)
              this.columnNames = columnNames;
         public void setRowData(Object[][] rowData )
              this.rowData = rowData;
         public int getRowCount() {
         return rowData.length;
         public int getColumnCount() {
              return columnNames.length;
         public Object getValueAt(int row, int col) {
              return rowData[row][col];
          public String getColumnName(int col) {
              return columnNames[col];
          public Class getColumnClass(int c) {
               if(c == 10 ){
                    return ImageIcon.class;
              return getValueAt(0, c).getClass();
          public boolean isCellEditable(int row, int col)
                if(col == 1)
                    return false;
               else
                    return true;
          public void setValueAt(Object value,int row,int col)
               this.rowData[row][col]=value;
          public Object getChanged_value()
             return changedValue;
          * Return the changed row number.
           public int getChanged_row()
             return changed_row;
          * Return the changed column number.
           public int getChanged_column()
             return changed_col;
           public Object[][] getData()
                return rowData;
           public void insertRow(int row, Object[] rowData) {
                elementData=rowData;
                for(int i=0;i<rowData.length;i++)
                     System.out.println("rowData["+i+"] "+rowData);
              dataVector=convertToVector(rowData);
    insertRow(row, dataVector);
    public void insertRow(int row, Vector rowData) {
         dataVector.insertElementAt(rowData, row);
         justifyRows(row, row+1);
    fireTableRowsInserted(row, row);
    protected static Vector convertToVector(Object[] anArray) {
    if (anArray == null) {
    return null;
    Vector v = new Vector(anArray.length);
    for (int i=0; i < anArray.length; i++) {
    v.addElement(anArray[i]);
    return v;
    private void justifyRows(int from, int to) {
              dataVector.setSize(getRowCount());
    for (int i = from; i < to; i++) {
         if (dataVector.elementAt(i) == null) {
              dataVector.setElementAt(new Vector(), i);
         ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
    public void removeRow(int row) {
    dataVector.removeElementAt(row);
    fireTableRowsDeleted(row, row);
    public synchronized void removeElementAt(int index) {
         modCount++;
         if (index >= elementCount) {
         throw new ArrayIndexOutOfBoundsException(index + " >= " +
                                  elementCount);
         else if (index < 0) {
         throw new ArrayIndexOutOfBoundsException(index);
         int j = elementCount - index - 1;
         if (j > 0) {
         System.arraycopy(elementData, index + 1, elementData, index, j);
         elementCount--;
         elementData[elementCount] = null;
    class TableTransferHandler extends StringTransferHandler {
    public JTable target;
    public int[] rows = null;
    public int addIndex = -1; //Location where items were added
    public int addCount = 0; //Number of items added.
    protected String exportString(JComponent c) {
    JTable table = (JTable)c;
    rows = table.getSelectedRows();
    int colCount = table.getColumnCount();
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < rows.length; i++) {
    for (int j = 0; j < colCount; j++) {
    Object val = table.getValueAt(rows[i], j);
    buff.append(val == null ? "" : val.toString());
    if (j != colCount - 1) {
    buff.append(",");
    if (i != rows.length - 1) {
    buff.append("\n");
    return buff.toString();
    protected void importString(JComponent c, String str) {
    target = (JTable)c;
    ExportEditTableModel model = (ExportEditTableModel)target.getModel();
    int index = target.getSelectedRow();
    System.out.println("index"+index);
    //Prevent the user from dropping data back on itself.
    //For example, if the user is moving rows #4,#5,#6 and #7 and
    //attempts to insert the rows after row #5, this would
    //be problematic when removing the original rows.
    //So this is not allowed.
    if (rows != null && index >= rows[0] - 1 &&
    index <= rows[rows.length - 1]) {
    rows = null;
    return;
    int max = model.getRowCount();
    if (index < 0) {
    index = max;
    } else {
    index++;
    if (index > max) {
    index = max;
    addIndex = index;
    String[] values = str.split("\n");
    addCount = values.length;
    int colCount = target.getColumnCount();
    for (int i = 0; i < values.length ; i++) {
    model.insertRow(index++, values[i].split(","));
    //If we are moving items around in the same table, we
    //need to adjust the rows accordingly, since those
    //after the insertion point have moved.
    if (rows!= null && addCount > 0) {
    for (int i = 0; i < rows.length; i++) {
    if (rows[i] > addIndex) {
    rows[i] += addCount;
    protected void cleanup(JComponent c, boolean remove) {
    JTable source = (JTable)c;
    if (remove && rows != null) {
    ExportEditTableModel model =
    (ExportEditTableModel)source.getModel();
    for (int i = rows.length - 1; i >= 0; i--) {
    model.removeRow(rows[i]);
    rows = null;
    addCount = 0;
    addIndex = -1;
    abstract class StringTransferHandler extends TransferHandler {
    protected abstract String exportString(JComponent c);
    protected abstract void importString(JComponent c, String str);
    protected abstract void cleanup(JComponent c, boolean remove);
    protected Transferable createTransferable(JComponent c) {
    return new StringSelection(exportString(c));
    public int getSourceActions(JComponent c) {
    return COPY_OR_MOVE;
    public boolean importData(JComponent c, Transferable t) {
    if (canImport(c, t.getTransferDataFlavors())) {
    try {
    String str = (String)t.getTransferData(DataFlavor.stringFlavor);
    importString(c, str);
    return true;
    } catch (UnsupportedFlavorException ufe) {
    } catch (IOException ioe) {
    return false;
    protected void exportDone(JComponent c, Transferable data, int action) {
    cleanup(c, action == MOVE);
    public boolean canImport(JComponent c, DataFlavor[] flavors) {
    for (int i = 0; i < flavors.length; i++) {
    if (DataFlavor.stringFlavor.equals(flavors[i])) {
    return true;
    return false;

  • How to set background color of row in JTable

    Hi,I want to set different background color to rows in JTable according to some value in the this row.
    eg.
    no name isGood
    1 aaa yes (this row's background color is red)
    2 bbb no (this row's background color is blue)
    3 ccc yes (this row's background color is red)
    4 ddd yes (this row's background color is red)
    5 eee no (this row's background color is blue)
    thanks

    thanks!*_*                                                                                                                                                                                                                                                       

  • How to set background color in row of JTable ?

    i am new in java please tell me about How to set background color in row of JTable ? please example code. Thnak you.

    Here is an example: http://www.javaworld.com/javaworld/javaqa/2001-09/03-qa-0928-jtable.html
    For more info on how to use tables read the swing tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    ICE

  • How to hide row in JTable?

    Hi all,
    How to hide some specific rows in JTable for user view filtering purpose?
    Thanks

    Try to use the Table Model.
    The "getValueAt" Methode decide what to Display.
    So a simple "if" command can hide the complete row - or a single Statement.
    public Object getValueAt(int row, int col) {
    ArrayList al = new ArrayList();
    StueliTeil tabellenzeile = (StueliTeil) getDaten().get(row);
    switch (col) {
    case 0 :
    return tabellenzeile.getUmfang();
    case 1 :
    return tabellenzeile.getTakt();
    ...

  • Inserting row in JTable (runtime)

    i need to inserting row in JTable in runtime so tell me what it do

    dear farhanaj ,
    try this code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    /* <applet code=tableadd.class width=200 height=200>
    </applet>
    public class tableadd extends JApplet implements ActionListener
    Object[] data = new Object[5];
    DefaultTableModel defaulttablemodel = new DefaultTableModel();
    JTable jtable=new JTable(defaulttablemodel);
    JPanel jpanel= new JPanel();
    private     JPanel          topPanel,jpPanel;
    public     JTable          table;
    JButton jbutton1 = new JButton("create new row");
    JButton jbutton2 = new JButton("create new col");
    //JButton jbutton1=new Jbutton("r"),jbutton2=new Jbutton("c");
    public tableadd()
    for(int column=0 ; column<5 ; column++)
    defaulttablemodel.addColumn("column" + column);
    for(int row=0 ; row<5;row++)
    for(int column=0 ;column<5;column++)
    data[column]="cell" row "," + column;
    defaulttablemodel.addRow(data);
    //getContentPane().add(new JScrollPane(jtable) ,BorderLayout.CENTER);
    //getContentPane().add(new JPanel() ,BorderLayout.SOUTH);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(jtable , v, h);
    getContentPane().add(jsp, BorderLayout.CENTER);
    topPanel = new JPanel();
    jpPanel=new JPanel();
    topPanel.setLayout( new BorderLayout() );
    getContentPane().add(topPanel,BorderLayout.NORTH);
    getContentPane().add(jpPanel,BorderLayout.SOUTH);
    jpPanel.add(jbutton1);
    jpPanel.add(jbutton2);
    jbutton1.addActionListener(this);
    jbutton2.addActionListener(this);
    public void actionPerformed(ActionEvent e)
    if (e.getSource() == jbutton1)
    int numberrows = defaulttablemodel.getRowCount();
    int numbercolumns=defaulttablemodel.getColumnCount();
    Object[] data = new Object[numbercolumns];
    for(int column=0 ; column<numbercolumns;column++)
    data[column]="cell" numberrows "," +column;
    defaulttablemodel.addRow(data);
    else
    if (e.getSource() ==jbutton2)
    int numberrows=defaulttablemodel.getRowCount();
    int numbercolumns=defaulttablemodel.getColumnCount();
    defaulttablemodel.addColumn("column" + numbercolumns);
    for(int row=0; row<numberrows ; row++)
    defaulttablemodel.setValueAt("cell" row "," +numbercolumns ,row , numbercolumns);
                   System.out.println(row);
    //jtable.sizeColumnsToFit(0);

  • How to set different font for a particular row in jtables?

    How to set different font size and font type for a particular row in jtable?

    More than enough sample code here:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]
    db

  • How to select a row in Jtable at runtime

    how to select a row in Jtable at runtime.

    use
    setRowSelectionInterval(int fromRowIndex, int toRowIndex);example if your table has 10 rows then u want to select the rows from 4 to 8 then use
    setRowSelectionInterval(3, 7);if you want to select just one row for example 5 then use
    setRowSelectionInterval(5, 5);

  • How to remove a row from JTable

    Hi!
    I'm used to remove rows from JTables getting the model and doing a removeRow(num) like this:
    ((DefaultTableModel)jTable1.getModel()).removeRow(0);
    But with ADF and JDeveloper the model says it's a JUTableBinding.JUTableModel but its not accessible.
    How to remove a row in Jdeveloper 10.1.3.4.0?

    Or maybe is just better to refresh data in the jTable but I do not know either like doing it.

  • How to forbid Column-Moving in a JTable ?

    Hi,
    anyone knoyw how to forbid the Column-Moving in a JTable ??
    I have a JTable that works fine, but it is still allowed to move the columns. And i want to forbid that.
    This: JTableHeader header = new JTableHeader();
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);
    did not work :-\
    Maybe someone has some ideas and could help me?
    Thx and have a nice day
    Avalon

    >
    Where's your thread, GoldieDork? You do nothing
    besides trolling.no I don't, I ask Java questions but no one answers them apart from the database question where dave and jverd and rage were all nice to me and I was happy that we could all be friends cos they helped me but then they started cussing me again so thats why I no longer talk to those guys.
    I dont know where my thread is now, Sun probably deleted it

  • How to apply different colors to specific rows in JTable

    hi,
    Anybody could tell me the way of colorising the rows in jtable.. I want to apply different colors to diff rows..
    If i get a piece of code that could help me a lot..
    thanks in advance,
    Sapna

    you'll find the answer at http://www2.gol.com/users/tame/swing/examples/SwingExamples.html

  • Delete row in JTable

    Hello I am new To JAVA SWING
    I have 2 questions related to JTable
    1) How do i remove selected row in JTable ...for instance, I click on the row to delete (It is selected) , later I press the delete button, and then row is removed .... any hints ?
    2) If I would like to save the rows in a JTable into a database , .... How can iterate through the rows in the JTable..each row .... the rows are saved in a List object...and a List Object is what I pass as a parameter in a class method in order to be saved into Database.
    Thanks,
    deibys

    1) use the removeRow(...) method of the DefaultTableModel
    20 use table.getModel().getValueAt(...) to get the data from the model and create your list Object.

  • Problem in adding/deleting rows in JTable

    I am trying to add /remove rows from JTable whose first column is JButton and others are JComboBox's.If no rows are selected,new row is added at the end.If user selects some row & then presses insert button,new row is added below it.Rows can only be deleted if user has made some selection.Kindly help me,where i am making mistake.If any function is to be used.My code is as follows....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    public class JButtonTableExample extends JFrame implements ActionListener{
    JComboBox mComboLHSType = new JComboBox();
    JComboBox mComboRHSType = new JComboBox();
    JLabel mLabelLHSType = new JLabel("LHS Type");
    JLabel mLabelRHSType = new JLabel("RHS Type");
    JButton mButtonDelete = new JButton("Delete");
    JButton mButtonInsert = new JButton("Insert");
    JPanel mPanelButton = new JPanel();
    JPanel mPanelScroll = new JPanel();
    JPanel mPanelCombo = new JPanel();
    DefaultTableModel dm ;
    JTable table;
    int currentRow = -1;
    static int mSelectedRow = -1;
    public JButtonTableExample()
    super( "JButtonTable Example" );
    makeForm();
    setSize( 410, 222 );
    setVisible(true);
    private void makeForm()
    this.getContentPane().setLayout(null);
    mPanelCombo.setLayout(null);
    mPanelCombo.setBorder(new LineBorder(Color.red));
    mPanelCombo.setBounds(new Rectangle(1,1,400,30));
    mLabelLHSType.setBounds(new Rectangle(26,5,71,22));
    mComboLHSType.setBounds(new Rectangle(83,5,100,22));
    mLabelRHSType.setBounds(new Rectangle(232,5,71,22));
    mComboRHSType.setBounds(new Rectangle(292,5,100,22));
    mPanelCombo.add(mLabelLHSType,null);
    mPanelCombo.add(mComboLHSType,null);
    mPanelCombo.add(mLabelRHSType,null);
    mPanelCombo.add(mComboRHSType,null);
    mPanelScroll.setLayout(null);
    mPanelScroll.setBorder(new LineBorder(Color.blue));
    mPanelScroll.setBounds(new Rectangle(1,28,400,135));
    mPanelButton.setLayout(null);
    mPanelButton.setBorder(new LineBorder(Color.green));
    mPanelButton.setBounds(new Rectangle(1,165,400,30));
    mButtonInsert.setBounds(new Rectangle(120,5,71,22));
    mButtonDelete.setBounds(new Rectangle(202,5,71,22));
    mButtonDelete.addActionListener(this);
    mButtonInsert.addActionListener(this);
    mPanelButton.add(mButtonDelete,null);
    mPanelButton.add(mButtonInsert,null);
    dm = new DefaultTableModel();
    //dm.setDataVector(null,
    //new Object[]{"Button","Join","LHS","Operator","RHS"});
    dm.setDataVector(new Object[][]{{"","","","",""}},
    new Object[]{"","Join","LHS","Operator","RHS"});
    table = new JTable(dm);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowHeight(25);
    int columnWidth[] = {20,45,95,95,95};
    TableColumnModel modelCol = table.getColumnModel();
    for (int i=0;i<5;i++)
    modelCol.getColumn(i).setPreferredWidth(columnWidth);
    //modelCol.getColumn(0).setCellRenderer(new ButtonRenderer());
    //modelCol.getColumn(0).setCellEditor(new ButtonEditor(new JCheckBox()));
    modelCol.getColumn(0).setCellRenderer(new ButtonCR());
    modelCol.getColumn(0).setCellEditor(new ButtonCE(new JCheckBox()));
    modelCol.getColumn(0).setResizable(false);
    setUpJoinColumn(modelCol.getColumn(1));
    setUpLHSColumn(modelCol.getColumn(2));
    setUpOperColumn(modelCol.getColumn(3));
    setUpRHSColumn(modelCol.getColumn(4));
    JScrollPane scroll = new JScrollPane(table);
    scroll.setBounds(new Rectangle(1,1,400,133));
    mPanelScroll.add(scroll,null);
    this.getContentPane().add(mPanelCombo,null);
    this.getContentPane().add(mPanelScroll,null);
    this.getContentPane().add(mPanelButton,null);
    }//end of makeForm()
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource() == mButtonInsert)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before Insert CURRENT ROW"+currentRow);
    if(currentRow == -1)
    int rowCount = dm.getRowCount();
    //mSelectedRow = rowCount-1;
    //table.clearSelection();
    dm.insertRow(rowCount,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    else
    table.clearSelection();
    dm.insertRow(currentRow+1,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("After INSERT CURRENT ROW"+currentRow);
    if(ae.getSource() == mButtonDelete)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before DELETE CURRENT ROW"+currentRow);
    if(currentRow != -1)
    dm.removeRow(currentRow);
    table.clearSelection();
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("Selected Row"+mSelectedRow);
    else
    JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
    //System.out.println("DELETE CURRENT ROW"+currentRow);
    public void setUpJoinColumn(TableColumn joinColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("AND");
    comboBox.addItem("OR");
    comboBox.addItem("NOT");
    joinColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    joinColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = joinColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpLHSColumn(TableColumn LHSColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Participant1");
    comboBox.addItem("Participant2");
    comboBox.addItem("Variable1");
    LHSColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    LHSColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = LHSColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpOperColumn(TableColumn operColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("=");
    comboBox.addItem("!=");
    comboBox.addItem("Contains");
    operColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    operColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = operColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpRHSColumn(TableColumn rhsColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Variable1");
    comboBox.addItem("Constant1");
    comboBox.addItem("Constant2");
    rhsColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    rhsColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = rhsColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public static void main(String[] args) {
    JButtonTableExample frame = new JButtonTableExample();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    //Button as a renderer for the table cells
    class ButtonCR implements TableCellRenderer
    JButton btnSelect;
    public ButtonCR()
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column)
    if (column != 0) return null; //meany !!!
    //System.out.println("Inside renderer########################Selected row");
    //btnSelect.setText(value.toString());
    //btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    return btnSelect;
    }//end fo ButtonCR
    //Default Editor for table
    class ButtonCE extends DefaultCellEditor implements ActionListener
    JButton btnSelect;
    JTable table;
    //Object val;
    static int selectedRow = -1;
    public ButtonCE(JCheckBox whoCares)
    super(whoCares);
    //this.row = row;
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    btnSelect.addActionListener(this);
    setClickCountToStart(1);
    public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column)
    if (column != 0) return null; //meany !!!
    this.selectedRow = row;
    this.table = table;
    table.clearSelection();
    System.out.println("Inside getTableCellEditorComponent");
    return btnSelect;
    //public Object getCellEditorValue()
    //return val;
    public void actionPerformed(ActionEvent e)
    // Your Code Here...
    System.out.println("Inside actionPerformed");
    System.out.println("Action performed Row selected "+selectedRow);
    btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    }//end of ButtonCE

    Hi,
    All the thing you have to do is to return a boolean for the column. JTable will use a checkbox (as default) to show boolean values.

  • Hide row in Jtable

    Please I need help
    How can I hide a row in Jtable.
    For example if you push a button hide first row.
    Thanks

    One simple way you can do is:
    just remove this row but keep it somewhere so that you may add it back when you want later. :-)

  • Selecting Row in JTable

    Dear friends,
    When i select a whole row in JTable it gets selected but the background color of the row selected does not change. i.e. Its not highlighted as in MS-Excel.
    How can i overcome this problem?
    Kindly reply
    Thanks.

    Hi,
    Thanx for ur inputs. This is what the code i wrote. When u run this code,
    If we select row1 column1 the cells highlighted will be on row 2, 3 and 4. If we select row1 column 2 the selected cells will be on row 1, 3 and 4. I want the row to be selected fully when we select coumn 1 only.
    For eg. if i select row 200 from column 1 the 200 th row should only be fully highlighted
    Anyway i'll try the above code and check
    Here is the code
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class table1 extends JFrame
         // Variables declaration
         private JTable jTable1;
         private JScrollPane jScrollPane1;
         private JPanel contentPane;
         // End of variables declaration
         public table1()
              super();
                this.setVisible(true);
         private void initializeComponent()
              jTable1 = new JTable();
              jScrollPane1 = new JScrollPane();
              contentPane = (JPanel)this.getContentPane();
              jTable1.setModel(new DefaultTableModel(4, 4));
              jScrollPane1.setViewportView(jTable1);
              contentPane.setLayout(null);
              addComponent(contentPane, jScrollPane1, 58,65,301,207);
              this.setTitle("table1 - extends JFrame");
              this.setLocation(new Point(0, 0));
              this.setSize(new Dimension(473, 539));
         private void addComponent(Container container,Component c,int x,int
    y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         } Thanks again

Maybe you are looking for

  • I want to install acrobat pro on my two computer

    how can I install acrobat pro on my two computer

  • Lines over watermark

    Hello, Is there anyway, using Crystal Reports designer, to have a watermark that appears below the boxes and lines in a report ? When I try to add lines or boxes in the watermark report sample given by Crystal, lines are always displayed under the wa

  • Removing Breadcrumbs in 11g

    Hi friends, Is it possible to remove the breadcrumb link in the discoverer viewer page in 11g. In 10g viewer, i can remove but dont know how to remove it in discoverer viewer 11g. Thanks Brgds, Mini

  • Netscape 6 & Java Plugin

    Hi, I am trying to write an Applet which will run in both Netscape and IE, using the Java Plugin. I have problems scripting the applet using Javascript when in Netscape - due to problems with Live Connect, I understand. I realise that Sun say Netscap

  • Firefox cannot open google

    Everytime i type in www.google.com I get this: The connection has timed out The server at www.google.com is taking too long to respond. I have a laptop which runs firefox and opens google just fine. I have cleared my cache and cookies and tried all t