Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:19:39+00:00 2026-06-01T16:19:39+00:00

i am writing java desktop application. i have some textareas to get data from

  • 0

i am writing java desktop application. i have some textareas to get data from user. A JButton, which takes input and process that. And a JTable to populate data processed.

here is my constructor em calling from main.

    public ChangeButtonLabel()
    {
        JFrame f=new JFrame();
            f.setLayout(null);

        JLabel lab1=new JLabel("Name");
            JLabel lab2=new JLabel("Age");

        //table=new JTable(model);

        text1=new JTextField(20);
            text2=new JTextField(20);


        button=new JButton("OK");

            lab1.setBounds(10,10,100,20);
            text1.setBounds(120,10,100,20);

            lab2.setBounds(10,40,100,20);
            text2.setBounds(120,40,100,20);

            Table=new ArrayList();
        Table.add(new ArrayList());
        ((ArrayList)Table.get(0)).add("\nProgram Name   ");
        ((ArrayList)Table.get(0)).add("Count   ");
        ((ArrayList)Table.get(0)).add("Elapsed Time   ");
        ((ArrayList)Table.get(0)).add("Average ET\n");

        button.setBounds(120, 100, 100, 20);        

        button.addActionListener(new MyAction());

            Object[][] data = {
                {"Program Name","count","ET","Avg ET"}
            };


        model = new DefaultTableModel(data,columnNames);

            dataTable = new JTable(model);

            dataTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
            dataTable.setFillsViewportHeight(true);

        dataTable.setBounds(220,130,300,200);
            f.add(lab1);
            f.add(text1);
            f.add(lab2);
            f.add(text2);

        f.add(dataTable);

        f.add(button);

            f.setVisible(true);
            f.setSize(300,350);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
    }
}

on event i am trying to update whole jtable, by deleting its previous values. here is the code

model = new DefaultTableModel(data,columnNames);
dataTable.repaint();
dataTable=new JTable(model);

    dataTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
    dataTable.setFillsViewportHeight(true);

dataTable.setBounds(220,130,300,200);

model.fireTableDataChanged();

Where data is 2d array, and columnames are columns.

But my JTable isnt getting updated.

Where i am doing wrong, please give me some direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:19:41+00:00Added an answer on June 1, 2026 at 4:19 pm

    You don’t want to create a new JTable since that has no effect on the currently displayed JTable. Instead you want to call setModel(...) on the current JTable and pass in the new table model.

    Also, please work on your code formatting since to be blunt, it stinks. Since you’re asking volunteers to put in effort to help you, I don’t think it’s asking too much for you to put in similar effort to not make it so difficult to read your code.

    Just as an example, check to see which is easier to read, your code above, or this code:

    public class ChangeButtonLabel {
       private JTextField text1;
       private JButton button;
       private ArrayList Table;
       private JTextField text2;
       private Object[] columnNames;
       private DefaultTableModel model;
       private JTable dataTable;
    
       public ChangeButtonLabel() {
          JFrame f = new JFrame();
          f.setLayout(null);
          JLabel lab1 = new JLabel("Name");
          JLabel lab2 = new JLabel("Age");
          // table=new JTable(model);
    
          text1 = new JTextField(20);
          text2 = new JTextField(20);
          button = new JButton("OK");
          lab1.setBounds(10, 10, 100, 20);
          text1.setBounds(120, 10, 100, 20);
          lab2.setBounds(10, 40, 100, 20);
          text2.setBounds(120, 40, 100, 20);
    
          Table = new ArrayList();
          Table.add(new ArrayList());
          ((ArrayList) Table.get(0)).add("\nProgram Name   ");
          ((ArrayList) Table.get(0)).add("Count   ");
          ((ArrayList) Table.get(0)).add("Elapsed Time   ");
          ((ArrayList) Table.get(0)).add("Average ET\n");
    
          button.setBounds(120, 100, 100, 20);
          button.addActionListener(new MyAction());
    
          Object[][] data = { { "Program Name", "count", "ET", "Avg ET" } };
          model = new DefaultTableModel(data, columnNames);
          dataTable = new JTable(model);
          dataTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
          dataTable.setFillsViewportHeight(true);
          dataTable.setBounds(220, 130, 300, 200);
    
          f.add(lab1);
          f.add(text1);
          f.add(lab2);
          f.add(text2);
          f.add(dataTable);
          f.add(button);
          f.setVisible(true);
          f.setSize(300, 350);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       }
    }
    

    Next we’ll work on use of layout managers…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Java desktop client application that retrieves data from a remote MySQL
I'm writing a Java SE 7 desktop application. I will need to store data
I am writing a desktop application written in Swing developed using Java 1.5. Some
I am writing java code. which will work on windows and linux. some code
I am writing a Desktop GUI application in Clojure using Java Swing. Normally when
I'm writing a Java SE (desktop) application that has to access different databases all
I am writing a java desktop application in netbeans. How can i make the
I am writing Java application, which is totally GUI-less. It runs in terminal through
I have a large tree of Java Objects in my Desktop Application and am
I am writing an application in Java for the desktop using the Eclipse SWT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.