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

Similar Messages

  • How to for JTextField and JButton..

    How can i set the size of the JTextField and getting the words alignment to be in Center format?? Can i use JButton, click on it and key in value to be displayed in text form?

    Hi,
    you can change the alignment really simple:
    JTextField textField = new JTextField("Your Text");
    textField.setHorizontalAlignment(JTextField.LEFT);
    textField.setHorizontalAlignment(JTextField.CENTER);
    textField.setHorizontalAlignment(JTextField.RIGHT);The size can be set by
    setPrefferedSize(int w, int h)or try
    setColumns(int columns)L.P.

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

  • 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

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

  • How to put a jpopup menue in a cell of jtable

    Hello,
    I want to make a jtable in which I want in one of the columns each cell when clicked(with right button) to pop up a jpopu menu with 3 actions. First I thought to make it with combobox but because I want to be activated with right button and then with the left i have changed my mind to jpopup menu.
    Can you tell me what kind of render and editor to use? I will be very grateful if you can send me some examples because I am new to the swing.
    Thanx,
    Miroslav

    You probably want to add a mouse listener to the JTable itself.
    There is some sample code below. It adjusts the location of the
    menu, and it's source component so that the menu can opperate
    on the proper object, rather than the source of the event.
    On your table add the menu as follows:
        table.addMouseListener(new PopupMouseListener(menu));You will have to decode the location to determine which column
    the "Right Click" occurred on. You may then have to decode the
    menu you want, (if you have different menus for different
    columns/cells).
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    import com.ovotron.util.Debug;
    public class PopupMouseListener extends MouseAdapter {
        private JPopupMenu menu    = null;
        private Component  invoker = null;
        public PopupMouseListener(JPopupMenu menu) {
            super();
            this.menu = menu;
        public PopupMouseListener(JPopupMenu menu, Component invoker) {
            this(menu);
            this.invoker = invoker;
        public void mousePressed(MouseEvent e) {
             int mod = e.getModifiers();
             if ((mod & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK) {
                 if (menu == null) {
                     return;
                 int       x     = e.getX();
                 int       y     = e.getY();
                 Component comp  = (Component)e.getSource();
                 if (invoker != null) {
                     // Event (X,Y), are relative to the source, need to
                     // re-calculate to be relative to the invoker.
                     Point src = comp.getLocationOnScreen();
                     Point loc = invoker.getLocationOnScreen();
                     x = x - (loc.x - src.x);
                     y = y - (loc.y - src.y);
                     comp = invoker;
                 menu.show(comp, x, y);
    }

  • How to put headers and footers in web analysis

    Hi All,
    Can anyone of you please let me know how to put headers and footers in web analysis...
    Thanks & Regards
    Ambica Atluri

    Hi Anu,
    I have already gone through the document. In that i dint find anything related to headers and footers.Only thing that is available is sorting the dimension headers.
    Please let me know if you have any other info regarding this.
    Thanks & Regards
    Ambica Atluri

  • How can I get right data in a cell of JTable when table  enter editing

    how can I get right data in a cell of JTable when table enter editing

    how can I get right data in a cell of JTable when table enter editing

  • JTextfield and JButton

    Hi all
    My problem is that i have a JTextfield that is connected to a Oracle database that allow the user to enter data in the database. I want to have a button that will allow the user to test to see whether the data entered in the textfield is valid.
    I'm not sure if i need to use sqlj or not. Any help would be gladly received.
    Thanks
    null

    Hmmm... lots and lots of ways to handle this, depending on your particular need for the particular type of 'validation'. ( More info? )
    "JTextField" is not connected to a database in the same way that the infoswing "TextFieldControl" is.. .therefore one could trap the event ActionPerformed off the JTextField and do the checks ( or use the jbutton like you suggest..but it would seem like you'd always want it checked and corrected before continuing towards the inevitable commit attempt??? ).
    You can use sqlj, or you can not use it... depends upon the way you've architected your application/environment and your needs and desires.
    Note (if you haven't already ) that you can also do a heck of a lot of validation at the entity/view object level.
    In my case ( an application ) I have a jdbc connection up at the front end for all my miscellaneous stuff, and a validate PL/SQL stored function. The nice things about using stored procedures/functions are that the validate routines can be nested for quick and easy use by triggers and stored procedures. If you put it outside the database it gets more fun should you want to get at the common validation routines from all approaches.
    Curious as to how other folk are architecting their validations....

  • JTextField and JButtons not appearing until clicked.

    I'm writing a program to refresh my CS1 java skills. For some reason when I try to add a JTextField and two JButtons to my container they don't appear until Ive clicked them.
    Actually more specifically, this only happens after a 100ms wait after setting the frame visible. Any less and the components wind up visible, but scrunched up in the top middle of my frame.
    Ive found that if I add the components before and after the wait they are visible and in the correct place, but this makes a noticeable flicker.
    I'm running windows vista if that matters.
    If someone could help me I would appreciate it.
    snippet of code:
    public scrollText()
         drawingThread.start();
         mainFrame.setSize(640,160);
         mainFrame.setContentPane(draw);
         mainPane = mainFrame.getContentPane();
         mainPane.setBackground(Color.white);
         mainFrame.setResizable(false);
         mainFrame.setVisible(true);
         try
              Thread.sleep(100);
              addInterface();
         catch(InterruptedException e){}
    public void addInterface()
         textInput.setBounds(1,103,501,31);
         play.setBounds(502,103,65,30);
         play.addActionListener(this);
         stop.setBounds(568,103,65,30);
         stop.addActionListener(this);
         mainPane.add(textInput);
         mainPane.add(play);
         mainPane.add(stop);
    }

    Postings can't be moved between forums. Now you know for the next time.
    The general form for building a GUI is
    frame.getContentPane().add( yourComponentsHere );
    frame.pack();
    frame.setVisible( true );Then all the compnoent will show up according to the rules of the layout managers used.
    However is you add components to the GUI "after" the GUI is visible then the components are not automatically painted. You need to tell the GUI to invoke the layout manager again so your code would be:
    frame.getContentPane().add( componentsToVisibleGUI );
    frame.getContentPane().validate();

  • How to put flash as a table or cell background or put HTML elements on top of flash file?

    Hi Guys,
    Could anyone please suggest me that how to put flash file as a table or cell background. I want to design a website and want to put HTML elements like table, images, text on top of flash file. so its look like animation in background. please visit following websites for an example: http://www.gagudju-dreaming.com/ and http://disneyworld.disney.go.com/
    Please guide me ASAP, thanks a lot in advance.
    Nitz.

    Hi Nitz
    The first thing you must do is convert your layout from table based to css based, (tables are o/k for tabular data, but not layout) but if you have never used css for layout it may be a steep learning curve.
    My recommendation is to start with the following tutorial on converting a table based comp to a css layout -
    http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt1.html
    More info on using css is available here - http://www.adobe.com/devnet/dreamweaver/css.html.
    Once you have converted your site the 'procedure' for using swf's as a background, (does not work well with flv's, but can be done using html5 video without a skin, to a limited extent) is the same as having a background-image resize automatically to the full browser view-port. The best way to learn how to do this is to view the code on a page using the background-image technique, view the code on this page - http://www.pziecina.com/indexold.php.
    However, instead of having a fluid layout I would recommend using a fixed layout size to start with, as this overcomes many problems. I have uploaded a basic test page to illustrate the idea to - http://www.pziecina.com/test_ideas/swfbg_test.html. As I said the page must be resized in this example in order to see the effect, (so do not forget to resize the browser, even if it is only by 1px), but if you use a fixed size layout and your swf's size fits the desired area correctly the resize should not be required.
    PZ
    www.pziecina.com

  • How to change the Background color of a cell in JTable

    hi!
    Actually i want to change the background color of few cells in JTable
    is there any method to make this change in JTable ?
    and also is it possible to have 5 rows with single column and 5 rows with 3 columns in a single JTable

    i want to change the background color of few cells in JTableDepending on your requirements for the coloring of cells it may be easier to override the prepareRenderer() method of JTable:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • How to put header and how to insert logo in this report

    HI
    I want  a header and logo in this report.how to do this in ALV report.Also why we have to put the          sy-repid.Plz tell me in this report where i have to do all this.Plz show me in detail.
    REPORT  ZREPORT_ALV .
    TYPE-POOLS : slis.
    tables:vbak,vbap.
    *DATA:  report_id LIKE sy-repid.
    DATA: I_LAYOUT TYPE SLIS_LAYOUT_ALV.
    data: ivariant(1) type c,
          itvariant like disvariant,
          w_variant like disvariant.
    initialization.
    *REPORT_ID = SY-REPID.
    PERFORM F1000_LAYOUT_INIT. "using I_LAYOUT.
    ivariant = 'A'.
    itvariant = w_variant.
    select-options:so_vbeln for vbap-vbeln.
    data:itab like vbak occurs 0 with header line.
    data:itab1 like vbap occurs 0 with header line.
    start-of-selection.
    select * from vbak into table itab where vbeln in so_vbeln.
    if not itab[] is initial.
    select * from vbap into table itab1
    for all entries in itab
    where vbeln = itab-vbeln.
    endif.
    data:ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat1  TYPE slis_t_fieldcat_alv.
    ****For alv display
    IF NOT itab1[] IS INITIAL.
       DEFINE ls_fieldcat.
       add 1 to ls_fieldcat-col_pos.
        ls_fieldcat-fieldname    = &1.
        ls_fieldcat-outputlen    = &2.
        ls_fieldcat-seltext_l    = &3.
         ls_fieldcat-emphasize  = &4.
        append ls_fieldcat to lt_fieldcat1.
        clear ls_fieldcat.
      END-OF-DEFINITION.
        ls_fieldcat 'VBELN'           '10'     'Sales Order Number'.
       ls_fieldcat 'POSNR'           '6'        'SO Item'.
        ls_fieldcat 'MATNR'           '13'      'Material No'.
    m_fieldcat1 'NETWR'           '13'        'Amount'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = 'wf_report'
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
    I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         =  I_LAYOUT
       IT_FIELDCAT                       =  lt_fieldcat1
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
      I_SAVE                            = ' '
      IS_VARIANT                        =   ITVARIANT
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
      TABLES
        T_OUTTAB                          =  itab1
    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.
    endif.
    CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
       I_SAVE              = ivariant
      CHANGING
       CS_VARIANT          = itvariant
    EXCEPTIONS
      WRONG_INPUT         = 1
      NOT_FOUND           = 2
      PROGRAM_ERROR       = 3
      OTHERS              = 4
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    FORM F1000_LAYOUT_INIT. "USING I_LAYOUT TYPE SLIS_LAYOUT_ALV.
    *CLEAR I_LAYOUT.
    i_layout-colwidth_optimize = 'X'.
    I_LAYOUT-key_hotspot = u2018Xu2019.
    I_LAYOUT-hotspot_fieldname =  MATNR.
    ENDFORM.

    hi,,,,
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = sy-repid >>>>>>>>>>>>> your report name.
    regarding logo and header,,,,
    first store the logo in T-code OAOR, then call that in your report.......
    data: heading        TYPE slis_t_listheader,
          wa_header      TYPE slis_listheader,
         events         TYPE slis_t_event.
    * To display TOP_OF_PAGE.
    FORM top_of_page.
      DATA : text(40),txtdt(40).
      CLEAR l_string.
      l_string = 'JCB India Limited'(hd2).
      wa_header-typ  = 'H'.
      wa_header-info = l_string.
      APPEND wa_header TO heading.                              " index 1.
      CLEAR l_string.
      WRITE :'Number of records:' TO text,dbcnt TO text+20 LEFT-JUSTIFIED.
      wa_header-typ  = 'S'.
      wa_header-info = text.
      APPEND wa_header TO heading.
      CLEAR l_string.
      wa_header-typ  = 'S'.
      WRITE : 'Report Run Date  :' TO txtdt,sy-datum TO txtdt+20 DD/MM/YY.
      WRITE sy-datum TO dat DD/MM/YY.
      wa_header-info = txtdt.
      APPEND wa_header TO heading.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          i_logo             = 'ENJOYSAP_LOGO'
          it_list_commentary = heading.
      CLEAR heading.
    ENDFORM.                    "top_of_page
    to execute top-of-page you have to create events.
    for ex......
    FORM create_event USING p_events TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = p_events.
      READ TABLE p_events WITH KEY name = slis_ev_top_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE formname_top_of_page TO ls_event-form.
        APPEND ls_event TO p_events.
      ENDIF.
    ENDFORM.                    " create_event

  • How to put material and service in the same order

    I want to put the material and service in the same order. How do it input different taxes. and also migo for one material item and other service item.

    HI,
    In your scenario create material and service PO using T-code ME21N as follows.
    1) Select PO document type, vendor and PO date
    2) PO first line item account assignment 'N' if project and give input data material code,plant,storage location,qty,rate,delivery date and tax code.
    3) PO second line item account assignment 'K', item category 'D',material short text for service, plant,storage location,material group data's are input given and press enter it will open 'Service Tab' in Item Detail Menu.
    4) In item Detail Menu - Service tab you will give Service no.,qty,gross price for the above  service material activity and service tax code in Invoice TAB and then check PO and SAVE.
    5) After getting PO approved by top management.
    6) PO first line item, you will do MIGO and PO second line item you will do ML81N service entry sheet.
    7) On the vendor bill, you will mention material document number (GRN no.) & Service sheet number and given to accounts dept.. They will book vendor bill and give payment.
    Hope, it is useful for you and solve your requirement.
    Regards,
    K.Rajendran

  • How to put AVCHD and AVI formats in a timeline using Adobe production suite?

    I shot an event with two different types of cameras (AVCHD camera and tape camera with AVI output). I converted the video of avchd into 1080p first, then put it with the tape output together, the video was jittery. How can I put them together in a timeline to have the best video as possible?

    The video was taken from capture card by using the adobe DV Format. I copied the settings of capturing bellow to give you more info of how I did it. I'm not sure if this the right way to do it.
    For editing with IEEE1394 (FireWire/i.LINK) DV equipment.
    Widescreen NTSC video (16:9 interlaced).
    48kHz (16 bit) audio.
    Drop-Frame Timecode numbering.
    General
    Editing mode: DV NTSC
    Timebase: 29.97fps
    Video Settings
    Frame size: 720h 480v (1.2121)
    Frame rate: 29.97 frames/second
    Pixel Aspect Ratio: D1/DV NTSC Widescreen 16:9 (1.2121)
    Fields: Lower Field First
    Audio Settings
    Sample rate: 48000 samples/second
    Default Sequence
    Total video tracks: 3
    Master track type: Stereo
    Audio Tracks:
    Audio 1: Standard
    Audio 2: Standard
    Audio 3: Standard
    The final output of the two format (AVCHD and .AVI) should be Widescreen 16:9
    thanks again for help me.
    Rolly
    Message was edited by: Rolly\'91

Maybe you are looking for

  • How to conf  in Hyperion, so the system couldn't login with the same user

    Hai..... how to configure in Hyperion, so the system couldn't login with the same user id in different machine ? (could you please provide me with detail step by step ? ) rgds uka fp

  • Pages-to-EPUB workaround

    Rather than jump down a rabbit hole on another thread, I opted to start a new Topic for those interested in a workaround workflow so that most of the formatting and inline graphics could be carried over into an .epub document. The article describing

  • Using a Document Listener to update a text field

    Hi, Background: I need to retrieve a number from a card using a hand scanner. I'm currently using a jTextField1 in Netbeans to do this. When the number is input (the format is 6 digits, i.e. 123456) the rest of the form fields are filled in and updat

  • Is there a BluRay DVD player for the HP HDX 9010nr?

    Is there a BluRay DVD player for the HP HDX 9010nr? This question was solved. View Solution.

  • String to column

    Hi experts, The data is as follows sno 1,2,3,4,5,6,7,8,9,10 I want to display it as SNO 1 2 3 4 5 6 7 8 9 10 Please provide me the SQL query. Thanks in advance.