java - access table model swing -
I wanted to make my application well without 100 internal squares and stuff. I have a class that holds some lists with the data. I have a menu, which uses the object action, such as I had to work there to remove the selected items from the table and work there. For this, I need reference for both table and table model. I want to add this action to the menu item, I will have to pass references to the table and table model which are created later as I do:
Main Menubar Menu = New Men Menu (DB); MainTabbedPane tabbed = new main tabbed pan (DB); This.setLayout (new border layout ()); Add (Menubar, Border Layout. PAGE_START); Add (Tabbed, Border Layout. CA);
Where TabbedPan has 2 tabs with 2 tables, so how can this do any good with any help?
It would be nice if JTable
supported generics, make life very easy But this is not because we do not like much.
Take advantage of a solution that will allow you
For example ...
Public abstract class AbstractTableAction & lt; M tablemodel extension & gt; AbstractAction {Personal JTable Table; Private M Model; Public Abstractable Action (Joint Table, M Models) {this.table = table; This.model = Model; } Public JTable getTable () {Return Table; } Public M getModel () {Return Model; }}
Then you can define the more focused functions ...
Public class DeleteRowAction extends AbstractTableAction
Now, obviously, MutableTableModel
is just an example, but there is a special implementation of TableModel
that gives you the necessary functionality Does.
From this perspective, you can apply these functions to jemanuitam
, pocketton
and key bindings, which means that you, for example Action for << Kbd> Delete , so that when focused on a table,
verb
will be triggered
You further define the abstract by defining any type of controller that provides access to the existing table / model, so you should only see the number A series of
s is required, which takes "Controller" as a reference, then the Controller will then provide reference to the current status of the scene / program (which is currently table / model active) ...
Comments
Post a Comment