3 jbuttons in a cell in a jtable

hi i have a problem entering 3 buttons into 1 cell i a jtable
can someone give me a good example how i put 3 buttons in the same cell
i have a button render and its working good with 1 button but i just cant find a way to enter 3 buttons in the same cell
tanks in advance

Doesn't sound like a good design, but if you must, have the renderer return a JPanel with the 3 buttons, probably in a GridLayout or BoxLayout.
I suppose you already know that the renderer only draws the components to the table cell, and your rendered buttons will not respond to mouse clicks or keyboard actions.
db

Similar Messages

  • How to put JTextfield and JButton in a cell of JTable

    I'm trying to put two Components into one cell of a JTable. This is no
    problem (in the TableCellRenderer) unless it comes to editing in these
    cells. I have written my own CellEditor for the table.but there is one
    minor problem: Neither the JTextfield nor the JButton has the focus so I
    can't make any input! Does anybody know what's wrong, please help me for this issue ,plese urgent

    Here you go
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    public class TableEdit extends JFrame
         JTable table = new JTable();
         private String[] columnNames = {"non-edit1", "edit", "non-edit2"};
         public TableEdit()
              super("Table Edit");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              createGUI();
              setLocationRelativeTo(null);
              setSize(400, 300);
              setVisible(true);
         private void createGUI()
              table.setModel(new DefaultTableModel(3,3)
                   public int getColumnCount()
                        return 3;
                   public boolean isCellEditable(int row, int column)
                        if(column == 1)
                             return true;
                        return false;
                   public String getColumnName(int column)
                        return columnNames[column];
                   public int getRowCount()
                        return 3;
                   public Class getColumnClass(int column)
                        return String.class;
                   public Object getValueAt(int row, int column)
                        return row + "" + column;
              table.setRowHeight(20);
              table.setDefaultEditor(String.class, new MyTableEditor());
              JScrollPane sp = new JScrollPane(table);
              add(sp);
         public class MyTableEditor extends AbstractCellEditor
         implements TableCellEditor
              JPanel jp = new JPanel(new BorderLayout(5,5));
              JTextField tf = new JTextField();
              JButton btn = new JButton("...");
              public MyTableEditor()
                   jp.add(tf);
                   jp.add(btn, BorderLayout.EAST);
                   btn.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e)
                             JOptionPane.showMessageDialog(null, "Clicked Lookup");
              public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
                   tf.setText(String.valueOf(value));
                   return jp;
              public Object getCellEditorValue()
                   return tf.getText();
         public static void main(String[] parms)
              new TableEdit();
    }

  • Urgent!!! JText and JButton in same cell of JTable

    Does anyone have an example of a JTable with a cell that allows for text input as well as a JButton for invoking the JFileSystemChooser. I believe this involves adding 2 JComponents to a cell within the JTable.
    An example of this can be seen if you have Visual Cafe. Under Tools, Environment Options, Virtual Machines. If you click in the cell for the VM Executable then click again (Without double-clicking), a JButton appears that when clicked will invoke the FileSystemChooser. Users have the option of either entering text or invoking the chooser.
    thanks

    You can create a TableCellEditor your self that inherits from a JPanel that contains a textfield and a button.
    class MyCellEditor extends JPanel implements TableCellEditor
    JTextField field = new JTextField();
    JButton button = new JButton("...");
    public MyCellEditor()
    // Add a textfield and a jbutton.
    this.setLayout(new BorderLayout());
    this.add(BorderLayout.CENTER, field);
    this.add(BorderLayout.EAST, button);
    // Add listeners
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
    // Initialize you editor's value.
    field.setText(value.toString());
    // What else?
    return this;
    public Object getCellEditorValue()
    return field.getText();
    // Implements other methods in the interface...
    Hope this helps.

  • Control the size for a JButton in a cell of JTable

    Hi,
    I am trying to add a column buttons on cells of a JTable. I followed the example from http://www.esus.com/docs/GetQuestionPage.jsp?uid=1285 and made it work (thanks).
    But, the buttons always resize to fit the column. Is there a way I can set button size, so the button will be smaller?
    Any information would be appreciated. Thanks in advance.

    Use a panel as a renderer and add the button to the panel, and manually set the preferred size of the button yourself. Then when the panel is added to the cell it will be resized, but the button will remain at its preferred size.

  • JComboBox Cell Editor in JTable

    I've scouered the forums for an answer to my question, and while
    finding other valuable advice, I have yet to find an answer to my
    question. But first, a little description:
    I have a JTable consisting of 5 columns:
    col1= standard Object cell editor
    col2= JComboBox cell editor
    col3= JComboBox cell editor, values dependent on col2
    col4= JComboBox cell editor, values dependent on col3
    col5= JComboBox cell editor, values dependent on col4
    Data structure looks like this:
    col1= company object, containing vector of values for col2
    col2= lease object, containing vector of values for col3
    col3= well object, containing vector of values for col4
    col4= pump object, containing vector of values for col5
    col5= simply displayed.
    I have a JButton that adds a new row to the table via dialog, then menu
    options to add entries to the comboboxes/vectors. The kicker here is
    that everything is fine up until I've added a pump, and click the cell
    to view the entry. In my cellEditor class, I have a 'getSelected()'
    method that returns 'combobox.getSelectedIndex()'. When 'edittingStopped()'
    is thrown for any cell in this column, I get a null pointer in my
    getSelectedIndex() method of the lease combobox - only in this pump
    column. Even the part column works correctly. Code snips:
    public class MyApplication ... {
      private TableColumn leaseColumn;
      private TableColumn wellColumn;
      private TableColumn pumpColumn;
      private TableColumn partColumn;
      private LeaseDropDown leaseDropDown;
      private WellDropDown wellDropDown;
      private PumpDropDown pumpDropDown;
      private PartDropDown partDropDown;
      private int currentLease = 0;
      private int currentWell = 0;
      private int currentPump = 0;
      public MyApplication() {
        leaseColumn = pumpshopTable.getColumnModel().getColumn(1);
        leaseDropDown = new LeaseDropDown(companies);
        leaseColumn.setCellEditor(leaseDropDown);
        DefaultTableCellRenderer leaseRenderer =
          new DefaultTableCellRenderer();
        leaseRenderer.setToolTipText("Click for leases");
        leaseColumn.setCellRenderer(leaseRenderer);
        //... same for lease, well, pump, part ...
        leaseDropDown.addCellEditorListener(new CellEditorListener() {
          public void editingCanceled(ChangeEvent e) {
          } // end editingCanceled method
          public void editingStopped(ChangeEvent e) {
            updateCells();
          } // end editingStopped method
        }); // end addCellEditorListener inner class
        //.... same inner class for well, pump, part ...
      } // end MyApplication constructor
      public void updateCells() {
        currentLease = leaseDropDown.getSelectedLease();
        //... get current well, pump, part ...
        leaseDropDown = new LeaseDropDown(companies); // companies=Vector,col1
        leaseColumn.setCellEditor(leaseDropDown);
        //... same for lease, well, pump and part columns ...
      } // end updateCells method
    } // end MyApplication class
    public class LeaseDropDown extends AbstractCellEditor
        implements TableCellEditor {
      private Vector companiesVector;
      private JComboBox leaseList;
      public LeaseDropDown(Vector cVector) {
        companiesVector = cVector;     
      } // end LeaseDropDown constructor
      public Component getTableCellEditorComponent(JTable table,
          Object value, boolean isSelected, int rowIndex, int vColIndex) {
        Company thisCompany = (Company) companiesVector.get(rowIndex);
        Vector leasesVector = (Vector) thisCompany.getLeases();
        leaseList = new JComboBox(leasesVector);
        return leaseList;
      } // end getTableCellEditorComponent method
      public Object getCellEditorValue() {
        return leaseList.getSelectedItem();
      } // end getCellEditorValue method
      public int getSelectedLease() {
        JOptionPane.showInputDialog("Selected lease is: " +
          leaseList.getSelectedIndex());
        return leaseList.getSelectedIndex();          
      } // end getSelectedLease method
    } // end LeaseDropDown class... LeaseDropDown can be extrapolated to well, pump, and part,
    handing well the selected lease, handing pump the selected
    lease and well, handing part the selected lease, well and pump.
    I guess my question is how do I get the selected comboboxitem (I'd
    settle for the entire combobox if there's no other way) to fill in the
    next column? Why does the way I have it now work for the first 2 combobox
    columns and not the third?

    I'll try to provide more details.
    I use a JComboBox implementation as a cell in a JTable. The CombBox is editable . This is what I get when I try to type in something.
    java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1507)
    at java.awt.Component.getLocationOnScreen(Component.java:1481)
    at javax.swing.JPopupMenu.show(JPopupMenu.java:921)
    at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:177)
    at javax.swing.plaf.basic.BasicComboBoxUI.setPopupVisible(BasicComboBoxUI.java:927)
    at javax.swing.JComboBox.setPopupVisible(JComboBox.java:790)
    at javax.swing.JComboBox.showPopup(JComboBox.java:775)
    I read some related bugs on the sun site but I am not sure if this is a bug and if it is then has it been fixed or work-around provided.
    any insights ??

  • Getting right end of text displayed in cells of a JTable column

    Hey All,
    Platform: WinXP, Java 5.0.
    I have a simple one-column table whose cells contain pathnames of user-selected files. The pathnames may be quite long, and when they're too long for the fixed width of the column (the containing JFrame is not resizable), I want the trailing (right) end of the pathnames to visible (so the filenames are visible) and for elipsis to be used on the left side (omitting root directory, etc., if need be). I can't figure out how to do this. I've tried many different approaches. Currently I use a class that extends TableCellRenderer, but no combination of alignment settings in this class seems to do the trick.
    I've noticed that in the case of JTextFields, this manner of display seems to be the default, no matter what alignment setting I choose. I can't seem to get the desired effect with the display of cells in my JTable though.
    Anyone have any suggestions?
    Thanks in advance.

    Great job camickr,
    That did just what I wanted; you get the points for sure! I will say that It's surprising to me that Swing leaves so much work in calculation to be done for this simple idea.
    Btw, I also want to mention here that there's another forum issue I raised and you responded to recently, and you never quite answered my question there:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5160875
    That's got 10 pts riding on it too, if you care to revisit the issue...
    Thanks very much for the good work on the CellRenderer.

  • How do I change the colour of text in a cell in a JTable?

    I am trying to change the color of the text in a single cell in a JTable. I have tried not adding a cell renderer and it changes the colour of text in all cells.
    I have tried adding a cell renderer to the table and it does the same ie all cells text colour changes.
    I am able to add a cell renderer to a column and it changes all the cells in the column.
    I cannot figure out how to change just one single cell's text colour without effecting the other cells.

    Ok, so if i create my own cell renderer do I set it as the default renderer for the whole table i.e.
    table.setDefaultRenderer(MyCellRenderer, renderer);
    Does this set one cell renderer for the whole table or is there an individual one for each cell?

  • 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 get the coordinate of a cell in the jtable?

    How to get the coordinate of a cell in the jtable?
    How to get the point of a cell in the jtable?
    Thanks for help!

    getCellRect(...);

  • How to enable JScrollPane in a cell of the JTable

    Hi,
    I am able to place the components into the cell of the JTable. But I am unable to interact with the components like JTable or JComboBox after inseting them into a cell of the JTable.
    This was the one of the Scenario:
    Step 1: I created One JTable named as "insertTable"and adding to JScrollPane
    Step 2: I'm able to inserted the newly created JTable ("insertTable") in to a cell of another JTable(like table inserting a table) using TableCellRenderer.
    here was the problem. I am able to insert the newly created table into the cell. the "insertTable" size is greater the Cell size. So, the "insertTable" is appering with Horizantal and Vertical Scrollbars because the "insertTable" is added to JScrollBar. but I am unable to move the scrollbars.
    please any one help me for this.

    you still didn't try to learn the difference between cellEditor vs cellRenderer - as you were advised to do more than once in recent posts.
    If you do, the answer will be obvious (to you :-). As long as you don't there's nothing to help
    Cheers
    Jeanette

  • How to insert textfield in a cell of a jtable ?

    Hi,
    i m not sure how to insert a textfield into a cell of a jtable which already contains some text in the cell .. Can anyone juz show mi a simple program to do this ??? thanks in advance =)

    Hi Michael,
    i get wad u r trying to say ermm actually i did that already. But wad i need to do is such that in a cell, there will b some text displayed (which i have done so) but i also need to add an additional box for user to enter the values n in this case i haf choosen to add the jtextfield box .. But i m not sure how to ... sorry for the misunderstanding ~~~ n thanks for ya reply =)

  • How can i add a MouseMotionlistener  to the cells in the JTable?

    hi !
    how can i add a MouseMotionlistener to the cells in the JTable?

    yes i have.but that is different from adding MouseMotionlistener to the cells for me .
    i just want get the values where the mouse moves to .

  • Help with editing a cell in a JTable. DESPERATE

    Hi! Is there someone out there that could help with some source code for editing a cell in my JTable when I run it as an applet??
    It works fine when I run it as an application.
    I manage to select the row and write a number in it, but I can't get out of the cell (it seems that the program stops??). I want to enter an integer in a cell and when I click enter or with the mouse in an other cell the value that I enter should update some other cell( multiply the entered value with some fixed number and update a cell in a second coloumn)
    I am really desperate now..... I have thought about using a MouseListener....
    I am using a tablemodel that is from AbstractTableModel.

    Are you using some cell editors?
    While converting inside them, you might be getting some exceptions (like parseexception)which is stopping you from proceeding further.
    Are you using your own tablemodel with custom datatypes?
    Hope this helps,
    Ramkumar

  • Making border of cell  invisible in JTable

    Hi i want to make border of cell invisible in JTable
    any help appreciated
    thanks in advance

    Create a renderer with no border - http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender .

  • How to do Multi Cell Selection in JTable

    Dear Friends,
    Any body know Multi cell selection in jtable......
    Thanks

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

Maybe you are looking for

  • T22 CD/DVD DRIVE ISSUES

    Hi can anyone help me i have a T22 running win98 and my CD drive will not read programme discs it plays dvds and music cds with no issues but will not run any programme discs. As the file that i downloaded from this site requires it to be run from fl

  • How can I solve this publishing error in iWeb?

    Suddenly, when I try to publish in iWeb, I get the following error message: Publish error: Can't create the file "site/home.html." The disk may be damaged or full, or you must not have sufficient access privileges Well, I have a Mac Pro tower, loaded

  • Nokia 701 lock slider problem

    Hi guys, i bought my 701 a month ago and i'm experiencing an annoying problem with the screen lock/unlock slider at the side of the device (probably after updating to Belle FP1) sometimes when i lock/unlock the screen it repeats the action twice, for

  • QOS for PCoIP on a 3850

    Teradici advises that packet loss be kept below 1% in PCoIP. I know that UDP is not guaranteed to arrive in order but, again according to Teradici, out of order packets may be considered as dropped packets.  One suggestion is to turn on WRED on the 3

  • Premiere EL 11 importing video from Internet

    Hi, I have been struggling undestanding how to properly manage video I download from the Internet and use in Premiere Elements 11. Most of the time I download from youtube with "Youtube Downloader HD" hoping that this is a valid tool to use and a lot