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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:58:34+00:00 2026-06-12T23:58:34+00:00

The scrollbar and the button will be painted but not the cells in the

  • 0

The scrollbar and the button will be painted but not the cells in the table,and the console has printed the data correctly so I am wondering where I have done wrong.

public class MyGUIManager extends JPanel {

    protected JFrame frame;
    protected JScrollPane scrollPane=null;
    protected JTable table=null;
    protected TableModel model=null;
    protected JButton btnInsert=null;

    protected String dbname,tblname;
    protected Vector<String> colNames;
    protected Vector<Vector<String>> data,backup;
    protected int col;

    protected MySQLGUIManager() throws Exception{

        frame =new JFrame("MySQL Manager");
        frame.setContentPane(this);
        frame.setMinimumSize(new Dimension(800,600));
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());
        init();
    }

    protected void init() throws Exception{
        //some inrrelevant operations about database
        loadTbl();
    }

    protected void loadTbl() throws SQLException{
        table=new JTable(data,colNames){
            private static final long serialVersionUID = 1L;
            public void tableChanged(TableModelEvent e){
                int column=e.getColumn();
                assert e.getFirstRow()==e.getLastRow():"more than 1 row have been changed!";
                int row=e.getFirstRow();
                if(scrollPane!=null){
                    //some codes
                }
            }
        };

        model=table.getModel();
        scrollPane=new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(scrollPane,BorderLayout.CENTER);
        btnInsert=new JButton("Insert a row");
        add(btnInsert,BorderLayout.SOUTH);
        repaint();
        revalidate();
//      scrollPane.repaint();
//      scrollPane.revalidate();
        System.out.println(model.getColumnCount()+" "+model.getRowCount());
        for(int i=0;i<data.size();i++){
            for(int j=0;j<data.get(0).size();j++){
                System.out.print(model.getValueAt(i, j)+" ");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) throws Exception {
        new MySQLGUIManager();
    }

}

(Some codes are omitted but they have nothing to do with GUI.)
Thanks in advance!

  • 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-12T23:58:35+00:00Added an answer on June 12, 2026 at 11:58 pm
    • Nothing is added to the data/column models
    • The data and column models are uninitialized
    • Creating a JFrame from within a JPanel only to add itself to the frame is bad practice

    You’re not call super.tableChanged from within you tableChanged method

    table = new JTable(data, colNames) {
        private static final long serialVersionUID = 1L;
    
        public void tableChanged(TableModelEvent e) {
            super.tableChanged(e);
            int column = e.getColumn();
            assert e.getFirstRow() == e.getLastRow() : "more than 1 row have been changed!";
            int row = e.getFirstRow();
            if (scrollPane != null) {
                //some codes
            }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The function works, but the popup will open only after the button is clicked
How to correctly resize scrollbar when underlying collection of a WPF ListView changes? I
I have a jQuery scrollbar in a static html page. The code works fine
I'm trying to draw a vertical scrollbar for my G15 applet, but am having
Okay there are 2 scenarios: I have a layout like this: ---------------- button header
I have an applet written using only AWT, that has a customizable bouncing ball
I have a div which has the content: <div id=First>There are lots of content
I have a window that will be a variable size , currently it is
The code below has (at least) two problems: the Copy button doesn't update the
I have a GridView that pulls data out of the database and populates its

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.