Display Fields in JTable

Hi I 've successfully created a JTable that connected to the MySQL databases that I've created previously. I am able to display the Table using Query like this :
rs = stmt.executeQuery("SELECT * FROM commenttable where tradeName like 'P%'");
However, I would like the user to be able to type in keywords in a textbox and search by click the search button and display the table according to the keyword.....But i don't know how to do it... hope someone can help me out here... Thanks beforehand~
Tony

ok it was really buggin me so i figured somethings out about your code.
the main problem is that your button event is not firing, this is due to where you have placed the code in your constructor. you should consider cleaning up your coding style and have your code in logical sections.
putting
System.out.println("button clicked");
in your button event listener informed me that its event wasnt firing when clicked. this was because you added the action listener to your button AFTER you had added the button to the panel, and the panel to the content pane. so it never got registered.
try this code for your program (it may not work straight away cos i changed some stuff to work with my database.) ive changed a lot of code around in your program but check it out.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class testing extends JFrame {
     private ResultSet rs;
     private Connection con;
     private ResultSetMetaData rsmd;
     private JTextField search;
     private JLabel jlsearch;
     private JButton jbtSearch;
     //ADDED THIS
     JTable table;
     JScrollPane scrollPane;
     Container c;
     public static void main(String args[]) throws Exception {
          testing app = new testing();
     public testing() {
          super("testing");
          try {
               Class.forName("com.mysql.jdbc.Driver").newInstance();
               con = DriverManager.getConnection(
               "jdbc:mysql://localhost/companyinfo?user=root&password=");
               catch (Exception e){
               System.err.println("Unable to find and load driver");
               System.exit(1);
          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          JPanel p = new JPanel();
          p.setLayout(new FlowLayout());
          p.add(jlsearch = new JLabel("Search: "));
          //ADDED THIS
          table = new JTable(10,10);
          table.setPreferredScrollableViewportSize(new Dimension(500, 70));
          scrollPane = new JScrollPane(table);
          search = new JTextField(10);
          jbtSearch = new JButton("Search");
          jbtSearch = new JButton("Search");
          jbtSearch.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                         System.out.println("button clicked");
                         queryDatabase();
          p.add(search);
          p.add(jbtSearch);
          c = this.getContentPane();
          c.add(p, BorderLayout.NORTH);
          c.add(scrollPane, BorderLayout.CENTER);
          pack();
          setVisible(true);
     public void queryDatabase() {
          System.out.println("querying");
          Vector data = new Vector();
          Vector rowSet;
          Vector tableNames = new Vector();
          int colCount = 0;
          String keyword = search.getText();
          try{
               con.setCatalog("companyinfo");
               Statement stmt = con.createStatement();
               rs = stmt.executeQuery("SELECT recordedTime, comment FROM commenttable where tradeName like '%" + keyword + "%'");
               //rs = stmt.executeQuery(query);
               rsmd = rs.getMetaData();
               colCount = rsmd.getColumnCount();
               tableNames.add("Recorded Time");
               tableNames.add("Comment");
               while(rs.next()){
               rowSet = new Vector();
               for(int i = 0;i < colCount; i++){
               rowSet.add(rs.getObject(i+1));
               data.add(rowSet);
          catch (SQLException e){
               e.printStackTrace();
          table = new JTable(data, tableNames);
          table.setPreferredScrollableViewportSize(new Dimension(500, 70));
          scrollPane = new JScrollPane(table);
          c.remove(1);
          c.add(scrollPane, BorderLayout.CENTER);
          c.validate();
}if it works, you owe me one cos i just spent an hour messing around with it. didnt have much else to do!!!!

Similar Messages

  • Regarding Selection Screen field making display field  in ALV report

    Hi All,
               In ALV Report,  at runtime how can i make the field as Display Field in selection screen .
    Thks & Regds
    Shailesh

    hii,
    Go to se38 and give the below progra name execute.... check the source code it is very easy to understand.
    1.demo_dynpro_modify_simple
    2.demo_dynpro_modify_screen
    if tou are using grid,u can refer to foll link
    sequencing / choosing fields in report screen at runtime,
    Display the Columns in the grid at run time
    rgrds,
    Shweta

  • Displaying fields from a Z Table on CRM UI

    Hello Experts
    I am trying to display fields from a custom table onto a CRM UI form view.
    1. I created a custom GENIL root object & Search object ie. ZCUSTOMER. & ZCUSTSEARCH
    2. Tested this in the GENIL BROWSER to ensure that I could enter update values to the table and retrieve it via the search object.
    3. Created a custom component ZCUSTOMER
    4. Created a view with this component ZCUSTOMER using the wizard -
         Model Name - CUSTINFO
         BOL Entity - ZCUSTOMER
         No links to the custom controller or higher level objects.(as I do not want to tie this to any standard components)
    Type of view - Form view
    7. Created a Context node for the component controller with the same info as I did for the view.
    8. Performed the binding of the view context node with the component controller context node.
    9. Configured 1 field CUST_NAME to be displayed on the view.
    10. Configured the run time repository to display the view.
    Now the issue is..
    When the view gets displayed, the field is displayed with the error "CUST_NAME not bound"
    What am i missing?
    Thanks
    RLX

    Hi Swati,
    Thanks for the feedback. I re-viewed the WD_CREATE_CONTEXT method of the view controller implementation class and I see the following code in there already-
    method WD_CREATE_CONTEXT.
      create the context
        context = cl_bsp_wd_context=>get_instance(
              iv_controller = me
              iv_type = 'ZL_ZCUSTOMER_BSPWDCOMPONEN_CTXT' ).
        typed_context ?= context.
    endmethod.
    Does that look right or do I need to modify it?
    Thanks once again for the help.
    RLX

  • How to get the value of a specific field in JTable

    hi every one,,,
    i'm intersting to get a field of JTable
    how can i decide the row and the column of JTable???
    and in which type will be the field ??

    If you need the row number of a selected row
    table.getSelectedRow() should work.
    If you are using a mouse then
    Point p = MouseEvent.getPoint();
    int row = table.getRowAtPoint(p);
    int column = table.getColumnAtPoint(p);
    You can set the type of the field in
    TableModel.getColumnClass(int column) method.

  • The number of rows displayed in a JTable

    Hi,
    Can anyone tell me how I choose the number of rows displayed in a JTable? My table displays 25 rows, and thats a bit too many.
    Thanks.

    You dont need to do much.. I think you just have to initialze the table with ..
    JTablt t = new JTable(rows,cols);
    and make sure to make the 'rows' parameter to whatever u want. :-)
    Cheers

  • Import Manager and Display Fields

    I've been using SRM-MDM 3.0 for a couple of months and 1 fundamental MDM design has always bothered me and I was hoping to get some resolve on this.
    The purpose of Display Field is 2 folds:
    1. Display the field in the Catalog Search UI for a lookup table: i.e. if both Supplier Name and ID are Display Fields, then in the Search UI, both fields are displayed to the end-user. If only Supplier ID was the display field, then in the UI only the ID is displayed.
    - From a usability pov, tables such as Supplier and Product Group should have the name or description fields displayed in the Search UI as the numeric values are meaningless to the end-users. 
    2. Display field ALSO affect what is the key used to import data into a table.  So if Supplier ID is the display field for Supplier table, then in Import Manager, the Supplier ID values are displayed and must be mapped to the source values.
    - From an importing pov, mapping values should always be an index-like field, such as Supplier ID or Product Group ID, or ISO, and usually never the actual name or description field.
    But SAP has tied the two together. So in order to display the name/description to the end-user, we must enable the name/description field as a Display Field.  But we also want to map based on the index/ID field, so we also enable the index/ID field as a Display Field.  Now in Import Manager, we have two Display Fields for a table (i.e. Supplier ID and Supplier Name for Supplier table) and I've noticed some issues with this:
    1. You import file must have BOTH values (index/ID and the name/description fields) in the source, in order to Automap.  If your source file only has 1 field, like in MECCM when extracting  ECC contract, ONLY the Supplier ID, or Category ID is extracted, Automap is not possible.  What is funny is that standard SAP extract program only extracts the ID fields, BUT the standard SAP repository has the name/description fields as the Display Field.  Automap is a must for tables like Product Group where hundreds of lines can make manual mapping a pain.
    2. I also noticed you cannot Add values to a table that has 2 Display Fields, you can only map to existing values.  The Add button is grayed out.
    With all that said, when you're replication ECC Contract Data using MECCM, for tables like Supplier and Product Group, what fields should be set as Display Fields, and if there are multiple Display Fields, what special setting needs to be done in Import Manager to enable automapping?  Even standard SAP Import Map (_MDMContractDataTransmission_ProductID) throws errors when multiple fields are set as Display Fields.
    I'm not familiar with the partitioning function, and I've seen PDF's about it, but don't really see how it could be helpful. I've also read someone suggesting changing the DF's before import, which I think is unacceptable, as this requires unloading/loading repositories everytime an import happens.
    Thanks for reading my paragraph and any input is greatly appreciated.
    Edited by: Derek Xu on Apr 30, 2009 6:50 PM

    Hi Derek,
    Thanks for writing your thoughts. I would like to provide some information on one of your points where in you have mentioned that :
    You import file must have BOTH values (index/ID and the name/description fields) in the source, in order to Automap. If your source file only has 1 field, like in MECCM when extracting ECC contract, ONLY the Supplier ID, or Category ID is extracted, Automap is not possible.
    I completely agree that if you have 2 fields in MDM repository and you are only importing only one of them, then you cannot use the Automap feature of Import Manager. So in your case, the description is not getting importing, so you cannot use Automap in that case.
    I had a very similar requirement in one of my project and we went with creation of a Import Value template. We created a template with all the possible values for all the look up tables in that and mapped it once in the Map. Hence, next time, the Map was used to automatically Map the source and Destination values for all the look up tables.
    SAP-MDM Automatic Import Requirement u2013 Creation of a Value Mapping Template:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80ad0cff-19ef-2b10-54b7-d4c7eb4390dd
    Please read the above article and hope its useful. You can go for this approach in your case if suitable.
    I have mentioned examples of descriptions and their respective fields in the article.
    Hope it helps.
    Thanks and Regards
    Nitin jain

  • How to display field information dynamically in reports

    How to display field information, depending on the description in DOMAINS..dynamically in reports...
    give an example.
    Thanks

    Hi
    the text u should take into the internal table for that and
    it should send into the ALV_GRID_DISPLY
    SLIS_FIELDCATALOG_T_ALV-SELECTION_TEXT = " DOMAIN".
    other wise u should set in the write statement
    write : / '     '.

  • How to display field values in long text of messages....

    Hi,
      Currently iam doing an userexit. In that i want to display error messages. and if we click on message it will display the long text. My question is i want to display field values in the long text. Under the long text's &system_response& i want  to display a field value.
    Regards
    chinna

    Hi Chinna,
    Within short and long texts, you can use placeholders, which can be replaced with the content of data objects using the MESSAGE statement. A maximum of four character-type placeholders are permitted; they are indicated by #&i# in short texts, and by #&Vi&# in long texts, where i = [1, 4]. If #&# itself is to be displayed as part of the text, it must be specified as #&&# in short texts and as "&" in long texts.
    To add some detail on how to create variables in Long text, you have to go to 'commands' and in symbol option provide the variables like
    &V1&  &V2&  and so on.
    Hope this helps you.
    revert for further clarification.
    <b>Alwyas reward Points to useful suggestions.</b>
    Regards,
    Vikas
    Message was edited by:
            Vikas Taneja

  • How to make a field in custom screen as display field in screen exit

    Hi ,
    I have created a screen exit for CO02 with a field for item text in header level as input field , when value is given and save button is cliked it gets updated in database but the problem is same field shows as input field in CO03 ( display mode ) .
    Code which i have used .
    in PBO
    if sy-tcode = 'CO03'.
    loop at screen .
    if screen-name cs 'SUBSCREEN' or screen-name cs 'RESB-POTX1'.
    ( subscreen - screen name given in screen editor and   resb-potx1 field name given in screen editor )
    SCREEN-INPUT = '0'.
    modify screen.
    endif.
    endloop.
    endif.
    and even i tried in PAI too .....
    if sy-tcode = 'CO01' or sy-tcode = 'CO02'.
    update resb set POTX1 = RESB-POTX1
    where aufnr = i_aufnr.
    elseif sy-tcode = 'CO03'.
    *oop at screen .
    *f screen-name cs 'SUBSCREEN' or screen-name cs 'RESBD-SORTF'.
    SCREEN-INPUT = '0'.
    modify screen.
    endif.
    endloop.
    endif.
    but itshows as input field only ........how to make that custom field as display field in CO03

    HI Andy,
    Try this out.
    FIrst check the sy-dynnr, if it is same as your custom screen number
    in PBO of your custom screen
    if sy-dynnr = 'YOUR_NUMBER' and sy-tcode = 'CS03'.
    loop at screen
    if screen-name = 'YOUR_SCREEN_NAME'
    screen-input = 0.
    modify screen
    endif
    endloop.
    endif.
    if it wont work they try using Tcode SHD0
    Hope this will serve your purpose.
    Regards
    Ramchander Rao.K

  • 1080i footage played in Viewer only displays field 1

    I'm using an iMac without an external monitor.  I have 1080i footage.  I can jog forward a field at a time and see both fields individually in the viewer.  But when played real time, my iMac only displays field 1.  Same thing if I play it back full screen.
    I know I wouldn't have this problem if I had an external monitor.  But is there a setting somewhere so the iMac will display both fields during playback?
    It's a 2011 iMac.  2.5 GHz Intel Core i5.
    THANKS.

    Thanks Tom.  Yes, with that setting both fields are displayed, but only when the sequence is paused.  You'll see both fields when paused, but only see field 1 when playing.
    You can forward a field at a time with Option and left or right arrow.  In Time Display, turn on "show subframes" in the Time Code display.  Field 1 is 00 subframes.  Field 2 is 40 subframes.
    Strangely, the Event Browser Display works differently.  In that window I can see both fields when it plays. And the "display both fields" in the Event Browser Display must have a bug.  It doesn't work for me, it always displays both fields.
    But in the main Viewer I only see field 1 while playing.

  • How to display back the JTable based on the coding??

    Hi all,
    I don't know how to display back my JTable after i remove it. I want the table to dissapear and reappear in given time. Hope someone can help me. Thanks a lot
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class tableTest extends JFrame implements ActionListener
         private String colNames[];
         private String rowData[][];
         private String col[];
         private String row[][];
         boolean stop = false;
         Timer timer;
         JScrollPane sp1=new JScrollPane();
         Container c=getContentPane();
         public tableTest(){
              super("table display");
              int delay=1000;
              timer = new Timer(delay, this);
            timer.setInitialDelay(0);
            timer.setCoalesce(true);
            timer.setDelay(1000);
              testing7(sp1);
              c.setBackground(Color.white);
                 Container c=getContentPane();
                 c.add(sp1,BorderLayout.WEST);
              System.out.println("haih~~");
              setBounds(50,50,600,600);
              setVisible(true);
         public static void main(String args[])
              tableTest test = new tableTest();
              test.start();
              test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public void actionPerformed(ActionEvent e)
                   start();
                   c.setForeground(Color.white);
                   c.remove(sp1);
                   System.out.println("Tested");
                   sleep();
                   stop();
                   testing7(sp1);
                   System.out.println("out!");
                   timer.restart();
        public void testing7(JScrollPane sp1)
              testing5();
              JTable t1= new JTable(row, col);
              t1.setRowHeight(20);
              t1.setGridColor(Color.red);
              sp1.getViewport().setView(t1);
              sp1.setPreferredSize(new Dimension(150, 150));
    //          c.add(sp1,BorderLayout.WEST);
    //          c.remove(sp1);
         public void testing5()
              testing3();
              testing4();
         public void testing3()
              col = new String[5];
              for (int i=0;i<5;i++)
                   col= " "+i;
         public void testing4()
              row = new String[10][10];
              for(int i=0;i<10;i++)
                   for(int j=0;j<10;j++)
                        row[i][j]=i+","+j;
         public void sleep()
              try
                   Thread thread;
                   Thread.sleep(2000);
              catch (Exception e){}
         public void start()
              if(stop)
              else
                   timer.start();
         public void stop()
              timer.stop();

    seegeorge,
    what do i mean by iconize it??

  • Page Item Drag and Drop reset all items Displayed Field attribute

    If I use the Drag and Drop feature it resets all items Displayed/Field attribute to yes. Is this just the way it is and it is to bad so sad for Nicholas or is there something I can do to be able to use drag and drop and still retain my setting for the Item's Displayed/Field attribute.
    Any assitance is much appreciated

    Probably the easiest way would be to have 2 arrays that hold
    the data being sent to box A. Just add/or subtract from one that
    you don't care if it changes, and leave the other one alone. When
    you want to reset, just clear Array 2 and populate it again from
    Array 1. For Box B, just reset the contents of the array to nothing
    - myArrayB = new Array({item1:'',item2:''})

  • [JHS 10.1.3.0.59] Error when generating Group with Display fields

    Do you already know this error in JAG when generating groups that contain items with display type 'display field'? Or am I doing anything wrong?
    [LovOrganizationTable.jspx, default/item/table/tableDisplayField.vm] Velocity log [error] ResourceManager : unable to find resource 'default/item/table/tableDisplayField.vm' in any resource loader.
    Toine

    Toine,
    Thanks for reporting, we should remove displayField from the list of dislay types. If you want a read-only field in 10.1.3, you can choose the proper display type, and then set "Insert Allowed" and "Update Allowed" properties to false.
    Steven Davelaar,
    JHeadstart Team.

  • Dropdownlist box value and display field retrieval question

    have a case on a dropdown list where I want to not only retieve the value from the selected item, but I also want to retrieve the display field. I know that you use the the tempDropdownlist.getValue() to get the value, but how do you retrieve the display field?
    The dropdown box is bound to a table with id(int) and Name(string).

    Yes there's no easy way - but you can loop thru the select items list and find the one that matches the current getValue result... and get it that way - see the tutorial on Using Listbox Components...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    hth,
    v

  • How to make Standard SRM fields as display fields on the screen

    Hi,
    I would like to make standards SRM field "PRODUCT ID" as the display field under the "BASIC DATA" tab.
    Is there any way to control the standard SRM fields on the Basic data of the SC?
    I have done it with custom fields with the BADI-BBP_CUF_BADI but it would not work for Standard SRM field.
    Thanks in advance.
    Mrudula Patel

    OK here is the solution.
    Create a Transaction variant via SHD0 Tcode
    In the transaction screen variant make the field display only.
    activate the transaction variant
    All the best.
    Let me know if any problems.
    Get me ur email id --- maybe i can you a document on how to create a screen variant and activate it.
    Message was edited by:
            Gummadi

Maybe you are looking for

  • IPhone won't play music imported from CDs or mp3s not downloaded from itunes

    When I first downloaded iOS 7, all of the music I had in my iTunes synched to my iPhone, but now new CDs I just imported and previous songs I imported from CDs won't synch (I've tried over wifi and usb).  When I click on songs on my phone that were f

  • Key being displayed instead of text for an infoobject.

    Hi, I have an infoobject DWBSELEMT for which the medium text is loaded in the text table. e.g. 1  EN  XYZ       2  EN  MNP This infoobeject is used in a cube and the cube is a part of the multiprovider. I have a BEx report on the multiprovider and DW

  • Combine two row in sql

    Hello Guys, Is it possible to create this kinda output. Input: Table1 Column1 Column 1 A 2 B 3 C 4 D Table2 A B C D 0 1 0 0 1 0 1 0 0 1 1 1 0 1 0 1 Output: B AC BCD BD Actually i want to Combine two different table column deepen where 1 . thanks

  • How do I merge events - not just combining pictures into one event?

    I have a iPhoto 09 and haven't upgraded yet. I have a bunch of events and it's hard to get through all of them. Can I combine the events while retaining the seperate events? Sort of an event within an event; not adding all the pictures from one event

  • How to change caller id for facetime on Iphone 5?

    How to change caller id for Facetime on Iphone 5? I cannot find anywhere I can make the change in Setting.