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

  • Home
  • SEARCH
  • 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 8607877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:28:17+00:00 2026-06-12T03:28:17+00:00

here is my code: public class DownloadMainView extends JFrame{ private ArrayList<DownloadItem> downloadList = new

  • 0

here is my code:

public class DownloadMainView extends JFrame{
    private ArrayList<DownloadItem> downloadList = new ArrayList<DownloadItem>();
    private JMenuBar menubar = new JMenuBar();
    private JMenu m_task = new JMenu("Tasks");
    private JMenu m_tool = new JMenu("Tools");
    private JMenu m_help = new JMenu("Help");

    private JMenuItem mi_add = new JMenuItem("Add");
    private JMenuItem mi_exit = new JMenuItem("Exit");
    private JMenuItem mi_options = new JMenuItem("Options");
    private JMenuItem mi_help = new JMenuItem("Help");
    private JMenuItem mi_about = new JMenuItem("About");

    private JTree categoryTree = new JTree();
    private JTable contentTable = new JTable(new Object[][]{},new Object[]{"No.","Filename","URL","Status","Size","Added Date"});
    private JToolBar toolbar = new JToolBar();
    private JScrollPane scrollPane = new JScrollPane();

    private JButton btnAdd = new JButton("Add");
    private JButton btnCancel = new JButton("Cancel");
    private JButton btnDelete = new JButton("Delete");
    private JButton btnOption = new JButton("Option");

    public DownloadMainView() throws IOException{
        super("KPDownloader");
        setSize(800,400);
        setLayout(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        //Build menubar
        menubar.add(m_task);
        menubar.add(m_tool);
        menubar.add(m_help);
        m_task.add(mi_add);
        mi_add.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK));
        m_task.add(new JSeparator());
        m_task.add(mi_exit);
        mi_exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.ALT_MASK));
        m_tool.add(mi_options);
        mi_options.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK));
        m_help.add(mi_help);
        mi_help.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
        m_help.add(mi_about);
        mi_about.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,ActionEvent.CTRL_MASK));
        setJMenuBar(menubar);
        //about buttons
        toolbar.add(btnAdd);        
        toolbar.add(btnOption);
        toolbar.add(btnCancel);
        toolbar.add(btnDelete);
        toolbar.setLocation(0, 0);
        toolbar.setSize(800,42);
        this.add(toolbar);
        //add table to mainview
        String columns[] = {"No.","Filename","URL","Status","Size","Added Date"};
        DefaultTableModel model = new DefaultTableModel(columns,1);
        readDownloadList();
        if(downloadList != null){
            int length = downloadList.size();
            for(int i = 0; i < length; i++)
                model.insertRow(i, new Object[]{i,
                        downloadList.get(i).getFilename(),downloadList.get(i).getSize(),
                        downloadList.get(i).getStatus(),
                        downloadList.get(i).getURL(),downloadList.get(i).getAddedDate()});
        }

        contentTable.setModel(model);
        contentTable.setSize(800, 350);
        scrollPane.add(contentTable);
        scrollPane.setSize(800, 350);
        scrollPane.setLocation(0, 50);
        this.add(scrollPane);

    }

But when I run my code, the table does not display column names. It just shows one empty row as I set 1 to this line: DefaultTableModel model = new DefaultTableModel(columns,1);

Please show me where my code is wrong??
Thanks!

Edited: As someone asked same question (No titles in JTable) but the answer is add Jtable to a JScrollPane and this does not help @@
Edited: Hi Dan, I’ve added my full Constructor, and here is the code of the readDownloadList() method:

void readDownloadList(){
            File file = new File("downloadlist.dat");
            ObjectInputStream ois = null;
            if(!file.exists())
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            try {
                ois = new ObjectInputStream(new FileInputStream(file));
                downloadList = (ArrayList<DownloadItem>) ois.readObject();
                ois.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                downloadList = new ArrayList<DownloadItem>();
                e.printStackTrace();
            }catch(ClassNotFoundException e){
                downloadList = new ArrayList<DownloadItem>();
                e.printStackTrace();
            }
        }

Thank you!

  • 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-12T03:28:19+00:00Added an answer on June 12, 2026 at 3:28 am

    You used the JScrollPane in a wrong way. To make it work fine, just do the following.

    Pass the JTable instance to the JScrollPane in the constructor:

    private JScrollPane scrollPane = new JScrollPane(contentTable);
    

    Comment out the line where you used to add the JTable to the JScrollPane:

    // scrollPane.add(contentTable);
    

    When you put the component inside the constructor of a JScrollPane, you mention which is the view to which the scroll to be applied for.

    On the other side, using the add method, you just add a component to a container, like adding it to a JPanel. This way, you don’t specify the component to add the scroll bars to.

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

Sidebar

Related Questions

Here is my code: public class XMLGettersSetters { private ArrayList<String> country = new ArrayList<String>();
So here's my code : public class SetWritable<T extends Writable> implements Writable { private
Here's my code: public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton;
here is my code public class SimpleJoglApp extends JFrame { public static void main(String[]
Here is my code... import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class
I've been working on this assignemnt here's code: public class Student { private String
here is my code: public class MainMenuActivity extends Activity implements OnClickListener { public int
Here's my code: public class Game extends JComponent implements Runnable { World w =
Here's my JFrame code: public static void main(String[] args) { JFrame jf = new
Here's the code: public class Deck { private Card[] cards; public Deck() { cards

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.