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.

Similar Messages

  • I want code on placing textbox and Jbutton in a cell of JTable.Please

    Dear All,
    Iam doing project on swing and XMl iam using swing for fron end design. Here i have to use table in one cell i have to put textbox and button. please can any body send me the code. Pleae iam waiting for your valuable code.
    regards,
    surya

    Hi I also want the same thing,
    My requirement is like this, The content of the table will be kept on changing using a thread connecting to the servlet. SO the record number will be different
    Can any one help me in this matter

  • I want code on placing textbix and Jbutton in a cell of JTable.Please

    Dear All,
    Iam doing project on swing and XMl iam using swing for fron end design. Here i have to use table in one cell i have to put textbox and button. please can any body send me the code. Pleae iam waiting for your valuable code.
    regards,
    surya

    instead of asking someone else to do the code and send it to you, why don't you try the code and submit it ot the forum for help?

  • 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();
    }

  • Calculate add and subtract to same cell?

    I have created a table that has numeric fields in them. I am trying to calculate from two fields and generate result in to one cell. for example, first column cell starts with beginning quantity, second column cell is to type number of quantity to remove from the beginning cell and third column to add to the beginning cell. the calculation should be populated in the fourth column cell. I am able to create add calculation script to fourth cell by just adding — Sum(begin1+add1) — but can’t figure out subtract to the same field.

    You are the best Steve!!! Thanks for your help

  • JButton inside the cell of JTable

    JButton buttonInCellOfTable = new JButton();
    buttonInCellOfTable.setBackground(Color.RED);
    buttonInCellOfTable.setText("MORE");
    buttonInCellOfTable.setPreferredSize(new Dimension(10, 22));
    buttonInCellOfTable.setMinimumSize(new Dimension(10, 22));
    buttonInCellOfTable.setMaximumSize(new Dimension(10, 22));
    myJTable.addRow("No. 1", buttonInCellOfTable);
    But Color and size isn't shown unlike those are set.
    What can I do?

    * @(#)ButtonTableCellRenderer.java     Tiger     2005 April 29
    package com.yahoo.ron.table;
    import java.awt.Component;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax,swing.JTable;
    import javax.swing.table.TableCellRenderer;
    * @author     Ronillo Ang - [email protected]
    final public class ButtonTableCellRenderer extends JButton implements TableCellRenderer{
         public ButtonTableCellEditor(ActionListener actionListener){
              super("Editor");
              if(actionListener == null)
                   throw new NullPointerException();
              addActionListener(actionListener);
         public Component getTableCellRenderComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int col){
              if(value instanceof String){
                   String text = String.valueOf(value);
                   setText(text);
              else
                   setText("Unknown value");
              return this;
    * @(#)TestingButtonTableCellRenderer.java      Tiger     2005 April 29
    package com.yahoo.ron.test;
    import com.yahoo.ron.table.ButtonTableCellRenderer;
    import com.yahoo.ron.table.UneditableTableModel;
    import com.yahoo.ron.ThreadMonitor;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    * @author     Ronillo Ang - [email protected]
    * A class to test com.yahoo.ron.table.ButtonTableCellRenderer
    public class TestingButtonTableCellRenderer implements ActionListener{
         public TestingButtonTableCellRenderer(){
              JFrame frame = new JFrame("Testing ButtonTableCellRenderer");
              frame.getContentPane().setLayout(new GridLayout(1, 1));
              JTable table = new JTable(new UneditableTableModel(new ThreadMonitor()));
              TableColumnModel tableColumnModel = table.getColumnModel();
              // get the last column.
              TableColumn tableColumn = tableColumnModel.getColumn(tableColumnModel.getColumnCount() - 1);
              // apply the cell renderer.
              tableColumn.setCellRenderer(new ButtonTableCellRenderer(this));
              frame.getContentPane().add(new JScrollPane(table));
              frame.pack();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
         public void actionPerformed(ActionEvent ae){
              // do nothing for now.
         static public void main(String[] args){
              new TestingButtonTableCellRenderer();
    // Okie!! I dont include my source of ThreadMonitor.java and UneditableTableModel.
    // If problem occur, make some modification. Okie!
    // Thanks! God bless you all!

  • 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.

  • I need to convert PDF to Excel, however, columns and tabs make many merged cells and many blank columns. In addition to not separate the columns correctly, I see many not separate lines together in the same cell. I'm even thinking that Adobe Acrobat Pro D

    I need to convert PDF to Excel, however, columns and tabs make many merged cells and many blank columns. In addition to not separate the columns correctly, I see many not separate lines together in the same cell. I'm even thinking that Adobe Acrobat Pro DC has limitations. There is no way to define what points in columns to force break column? Nor create many columns that are useless? How does text to column in Excel, fixed size when we import text, and define where the breaks have columns?
    Google Tradutor para empresas:Google Toolkit de tradução para appsTradutor de sitesGlobal Market Finder
    Desativar tradução instantâneaSobre o Google TradutorCelularComunidadePrivacidade e TermosAjudaEnviar feedback

    PDF does not contain columns, rows, formats, styles, or other aspects of word processing or spreadsheet file formats.
    This is because PDF is decidedly not a word processing or spreadsheet file format or something "like" one of those.
    (see ISO 32000 for what PDF "is")
    What can optimize the export of PDF page content is to start with a well-formed tagged PDF (ISO 14289-1, PDF/UA-1 compliant).
    Without that export is what it is and one performs whatever content cleanup is needed using the native application for the export file (MS Word or Excel).
    Be well...

  • Can we put text and button together in the same cell of ALV?

    Can we put a button and text in a cell of ALV Grid?
    Requirement in detail:
    Material Description + button - when the button is clicked, it opens up a screen to enter text.
    I able to open the screen ob button click but..
    when  I concatenated the material description and an icon, it showing garbage in ALV output.

    Hi,
    I think it is possible..check this code..I believe this also depends on the GUI version..Mine is 6.40 patch level 32....in my output it is showing icon with the text in one column...
    TYPE-POOLS slis.
    INCLUDE <icon>.
    TYPES: BEGIN OF type_data,
             matnr TYPE matnr,
           END OF type_data.
    DATA: t_fcat TYPE slis_t_fieldcat_alv.
    DATA: s_fcat TYPE LINE OF slis_t_fieldcat_alv.
    DATA: t_data TYPE STANDARD TABLE OF type_data.
    DATA: s_data TYPE type_data.
    * Field catalog.
    s_fcat-fieldname = 'MATNR'.
    s_fcat-row_pos    = '1'.
    s_fcat-ref_tabname = 'MARA'.
    s_fcat-ref_fieldname = 'MATNR'.
    APPEND s_fcat TO t_fcat.
    CONCATENATE icon_negative 'test matnr' INTO s_data.
    APPEND s_data TO t_data.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
        it_fieldcat   = t_fcat
      TABLES
        t_outtab      = t_data
      EXCEPTIONS
        program_error = 1
        OTHERS        = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Thanks
    Naren

  • Border and font setting for the same cell

    I have writen a label in an excel cell using a font that I created (called "wf" - see code below).
    I also want to put a left thick border to the same cell.
    How can I do that?
    ps: I call this function from "main":
    private static void writeDataSheet(WritableSheet s)
    WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
    WritableCellFormat cf = new WritableCellFormat(wf);
    Label l = new Label(1,0,"Last Name",cf);
    s.addCell(l);
    What code should I add to the upper function in order to set a left thick border to my cell?

    this issue has been solved

  • Mulitple Cell selection  with unselect the same Cell

    Dear Friends,
    I am having a JTable with a Multiple Cell Selection .Consider Now iam
    selecting the cell (0,3) (0,5) (1,7).When selecting the cell it is in Red color.
    I made this multi selection by using the setCellRenderer method overriding.It works fine.
    Now I am clicking the Same above cell with right click button in the mouse ..it must unselect ....means It may change the color too.
    Any body know about this....Can u please help me ...This is very urgent for me........
    Kindly
    malar

    Thanks friend,
    I have finished that..Now its working fine....
    I used the same cell renderer with deleting the existing index which was selected....And I called the repaint() again....Now it unselected.
    Thanks for ur simple and cute Idea....Thanks a lot

  • When I update a cell in one file folder I want that same cell

    When I update a cell in one file folder called (X)  I want that same cell to updated in a different file folder called (Y).  Can this be done?

    Question asked and answered many times.
    There is no link between Numbers documents !
    I already posted an AppleScript filling this hole.
    Yvan KOENIG (VALLAURIS, France) dimanche 7 août 2011 15:44:03
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please :
    Search for questions similar to your own
    before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • How to align text at the top and bottom of a cell?

    I'm making a periodic table and need help with aligning text at the top and bottom of a cell. I'll have a picture in the middle of the cell with text above and below the pic. Thank you in advance for any kind of suggestions you can give me.

    It sounds as though you want to have 3 separate items inside of a single cell; text at the top of the cell, text at the bottom of the cell, and then a picture in the middle of the cell.  I am no expert, but to my knowledge that is not possible (someone please correct me if I am wrong.)  I also cannot figure out how to put a picture inside of a cell itself.
    I do have a way to accomplish the end result so long as what you need is the final look and not a useable table in numbers.
    Create 2-3 cells for each element.  (The middle cell, unless you can put pictures in a cell and I don't know, would just be there for peace of mind, but would hold the picture if you can, I would just do two if the pictures are to be in front of the cell anyway.)  The top cell align text to top on the Text tab of the inspector.  The bottom cell, align text to bottom on the same tab.  Then place the picture in the middle.  Now, you have what you want except there is one or two lines dividing the cells.  To get rid of this, either click the middle cell if you have one, or the top or bottom cell.  Click on the Cell tab of the inspector.  Select the bottom border and/or top border button and select "No Border" under border styles.  To make this fast, select a full row at a time, or use command click to select all of the same type of rows (middle, top, or bottom) and change all cells at once.
    I hope this helps.  Best of luck!
    ~Bret

  • How to add text after number in the same cell? "200 units", "3Kg", "17 sqm"

    Dear Sirs,
    I have problem with adding text after a number in the same cell.
    For instance, in excel I am able to do this:
    200 units -----> this is on the same cell. Any number I type, "units" will follow automatically.
    I know that we can just type "200 units" but its in text format so it cannot be calculated supposedly I want to multiply it by others number.
    I know that we can do this by splitting into two cells, one on the left for the number "200" and another one on the right for the text "units".
    It would be helpfull if we could do this function such as "20 years", "3Kg" etc.
    Sorry to trouble you all.
    Thank you
    Q

    This is a case of uneven implementation in Numbers. This sort of functionality is available to format numbers used to label axis ticks on various charts, but not to format numbers in a cell. This feature should be requested.
    As an aside, perhaps a spreadsheet that actually managed numeric units as part of the calculation would be powerful and useful in avoiding formula bugs, something like is available in Google calculations. If you are unfamiliar with this, try one of the following examples typed into any Google search entry field:
    150 miles per gallon in liters per 100 kilometers
    100 * 20 yards / 40 minutes in mph
    Read more at http://www.google.com/intl/en/help/features.html#calculator

  • Ask split long text into two line into same cell for ALV

    Dear All,
    Is it possible split long text into two line into same cell for ALV display data?
    Regards,
    Luke
    Moderator message: please search for information before asking.
    Edited by: Thomas Zloch on Feb 24, 2011 10:12 AM

    Keep options: Select the paragraph, then CtrlAltK (Mac: CmdOptK, I
    think).
    If you want the paragraphs in pairs, create two paragraph styles. Style
    A has keep options set to start on a new page, and also, its Next Style
    is style B.
    Style B has no keep options, but it's Next Style is Style A.
    Select all the text.
    From the flyout menu of the paragraph styles palette, apply Style A
    "then next style."
    Now all paragraphs will be alternating -- style A, style B, style A, etc.
    Now do what I wrote initially, and you'll have pairs of paragraph in
    separate text frames.

Maybe you are looking for

  • Header Fields not picked in Http Adapter

    Hi , I am sending a few custom header fields that have been set up in the HTTP adapter but for some reason they are not picked. Any suggestions.. -Teresa

  • Nokia C3-01 won't start up after sw update

    Hi, I have just updated my firmwire for C3-01. After that the phone switched off automatically, but when I tried to restart my phone. The screen only displyaed whie background and turned off, and displayed white bacground again. Dose anyone know how

  • My MacBookPro only connects to Internet via a WiFi hotspot

    New MacBookPro laptop with OS 10.8.4 with Airport turned on connects via WiFi hotspot to internet but will not connect wirelessly to Internet via modem and router connected to cable service.  Will also not connect via Ethernet to modem and router to

  • Subscription has reverted to Free account settings

    We received (19/03/15) information via email that "Your FormsCentral subscription has expired, but we hope you'll continue enjoying our services as a free member." I understood that we would be able to use the account at the 'Regular' settings until

  • Parse a CSV file every 1hour

    hi all, i am working on this app, in which i need a parse a CSV file every 1hr. now the CSV file is average size. i need to parse the file (i will use simple stringtokenizer), organise the data in the file (using simple string manipulation) and expor