Results 1 to 4 of 4
  1. #1
    Aiquoc is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default Assigning text in JTable by clicking a button

    Hi,
    Just wanted to ask, how do I assign a text from a text field to a table after I click a button?

    I got a text field where I enter a name and when I click a button the name would be transferred on a table.

    Thanks.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    I imagine it would be something like:

    Write an ActionListener class with an actionPerformed method.
    Get the text from the textfield.
    Get the TableModel.
    Set the required cell in TableModel to text from textfield.
    Repaint.

    If any of those steps are unfamiliar then read the Java API and/or a tutorial. Write some code and if you get stuck come back and post your code and ask a specific question.

  3. #3
    Tedward is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    He is mostly right, you have to get the text from the field first and store it as a "public static String" variable. Something like this...

    Java Code:
    public static String username;
    
    public String getUserName()
        {
        username = first.getText();
        return username;
        }
    Then just call the method and do what Junky said and that should work.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

Similar Threads

  1. Creating a textfield on clicking toolbar button
    By rohaniiitb in forum SWT / JFace
    Replies: 0
    Last Post: 02-14-2011, 12:18 PM
  2. How to open new JFrame with clicking on button?
    By phearless in forum AWT / Swing
    Replies: 1
    Last Post: 01-14-2011, 10:36 AM
  3. Replies: 3
    Last Post: 08-07-2010, 08:06 PM
  4. right clicking JTable row
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 06-27-2010, 11:41 PM
  5. Get source web page after clicking next Button
    By noob in forum New To Java
    Replies: 1
    Last Post: 03-05-2010, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •