Creating a class that extends JTable

I have a JTable in my panel and I would like to make a different class for it.

Here is my original code:

   Object[][] data = {
        {" A", ""},
        {" B", ""},
        {" C", ""},
        {" D", ""},
        {" E", ""},
        {" F", ""},
        {" G", ""},
        {" H", ""},
        {" bonus", ""},
        {" Total", ""}
    };

    String[] columname = {"", ""};

    JTable tabelscor = new JTable(data, columname);
    tabelscor.setBounds(500, 120, 160, 250);
    tabelscor.setEnabled(false);
    add(tabelscor);

I would like a class that would include the data and columname, so I don't have to create them in my main class, and I would declare the table with myTable table = new myTable();

Answers


If you'd like to extend JTable, you will still need to set the properties from outside of the class. I'm pretty sure you would be better of using a Populator or anything similar. This would be a class between your original class and the JTable that generates the JTable for you (and if desirable, returns it to the first class).

Example

class MyMain {
    void someMethod() {
        JTable table = (new Populator()).createJTable();
        add(table);
    }
}

class Populator {
    Object[][] data = {
        {" A", ""},
        {" B", ""},
        {" C", ""},
        {" D", ""},
        {" E", ""},
        {" F", ""},
        {" G", ""},
        {" H", ""},
        {" bonus", ""},
        {" Total", ""}
    };

    String[] columname = {"", ""};

    JTable createJTable() {
        JTable tabelscor = new JTable(data, columname);
        //tabelscor.setBounds(500, 120, 160, 250);
        tabelscor.setEnabled(false);

        return tabelscor;
    }
}

Need Your Help

How to implement “where” clause in linq

c# linq

May query needs to identify id or I should say group of ids in a collection, may query is like this

specify static variables in a python class in C++

c++ python class static cpython

How would one go about specifying a static method or variable in a python class, in CPython C++?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.