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 7695813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:37:57+00:00 2026-05-31T21:37:57+00:00

I have a JTable inside a JScrollPane. After calling my function which should populate

  • 0

I have a JTable inside a JScrollPane. After calling my function which should populate the table I can’t see any changes! I’v tried with table.repaint(), model.fireTableDataChanged() and probably some other stuff that I can’t remember anymore – nothing worked. What am I doing wrong??

My function:

public static void fillVodicTable(JTable table){

    DefaultTableModel model=new DefaultTableModel(); //also tried (DefaultTableModel)table.getModel();
    table.setModel(model);
    model.setColumnIdentifiers(new String[]{"Ime", "Priimek", "Epošta", "Datum rojstva", "Licenca", "Jeziki"});
    String [] row={"a","b","c","d","e","f"};

    model.addRow(row);
}
  • 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-05-31T21:37:58+00:00Added an answer on May 31, 2026 at 9:37 pm

    1) there no reason call for model.fireTableDataChanged() for DefaultTableModel

    2) there no reason call for table.repaint(), is useless

    3) what’s for(Jezik j : v.getTuji_jeziki()) row[5]+=", "+j.toString(); there could be more than 100% ** of your issues

    4) DefaultTableModel works in all cases, but requierd only update on EDT, in other hands this is common issue for all Swing JComponents together

    5) for better help sooner edit yout question with a SSCCE

    6) EDT == Event Dispatch Thread

    7) SSCCE

    • DefaultTableModel

    • model.addRow(row);

    • Short

    • Self Contained

    • Correct

    • Example

    then

    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    import javax.swing.*;
    import javax.swing.border.LineBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    
    public class DefaultTableModelDemo {
    
        public static final String[] COLUMN_NAMES = {
            "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
        };
        private DefaultTableModel model = new DefaultTableModel(COLUMN_NAMES, 0);
        private JTable table = new JTable(model);
        private JPanel mainPanel = new JPanel(new BorderLayout());
        private Random random = new Random();
    
        public DefaultTableModelDemo() {
            JButton addDataButton = new JButton("Add Data");
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(addDataButton);
            addDataButton.addActionListener(new ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    addDataActionPerformed();
                }
            });
            model = new DefaultTableModel(COLUMN_NAMES, 0) {
    
                private static final long serialVersionUID = 1L;
    
                @Override
                public Class getColumnClass(int column) {
                    return getValueAt(0, column).getClass();
                }
            };
            table = new JTable(model) {
    
                private static final long serialVersionUID = 1L;
    
                @Override
                public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                    Component c = super.prepareRenderer(renderer, row, column);
                    if (isRowSelected(row) && isColumnSelected(column)) {
                        ((JComponent) c).setBorder(new LineBorder(Color.red));
                    }
    
                    return c;
                }
            };
            mainPanel.add(new JScrollPane(table), BorderLayout.CENTER);
            mainPanel.add(buttonPanel, BorderLayout.SOUTH);
        }
    
        private void addDataActionPerformed() {
            for (int i = 0; i < 5; i++) {
                Object[] row = new Object[COLUMN_NAMES.length];
                for (int j = 0; j < row.length; j++) {
                    row[j] = random.nextInt(5);
                }
                model.addRow(row);
            }
        }
    
        public JComponent getComponent() {
            return mainPanel;
        }
    
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    JFrame frame = new JFrame("DefaultTableModelDemo");
                    frame.getContentPane().add(new DefaultTableModelDemo().getComponent());
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable inside a JScrollPane; How can I get the JTable? Thanks
I have a JTable inside of a JScrollPane . I am creating a custom
So I have a bunch of JTable s. Each JTable is inside a JScrollPane
I have the following problem: I have a JTable inside a JScrollPane, and the
If I have a jTable ( inside a jScrollPane ) with 1000+ columns. Is
I have a jTable which currently displays and allows editing of a database table,
I have a JPanel that contains a JScrollPane that contains a JTable. Inside my
I have a JTable inside a JScrollPane. In one of the columns in the
I have a JTable that is within a JScrollPane. Rows are added to the
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this

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.