Amir
Amir

Reputation: 1979

How I can add a JTable to a class extended from JScrollPane?

I want to create a class and extend it from JScrollPane than I want to add a customized table to it, I want to know is it possible or not? I put my sample code here

Can I create my table after I call super?

import javax.swing.*;

public class myJtableButton extends JScrollPane {
    private JTable __table;
    private JScrollPane __scrollPane;
    private String TableName;


    public myJtableButton(String TableName) {
        super(__table);
        __table = new JTable();

        this.TableName = TableName;

    }
}

Upvotes: 2

Views: 964

Answers (1)

jzd
jzd

Reputation: 23629

Yes you can create such a class. Just don't call super in your constructor. Instead create your table and then set the view of the scroll bar like this:

setViewportView(table);

Upvotes: 4

Related Questions