Interacting with the cell of a custom jTable - java

I created a custom table, with a custom model, a custom cell renderer and a custom cell editor. Every cell of this table is a panel which contains another custom table.
The problem is: (with or without the internal table) to interact with the cell, thus to trigger the event listener of the components in that cell(which is a panel), you need to click the table before.
I imagine it wants you to "enter the table" or select the cell before you can actually interact with its components but this is not functional.
Is there a way to avoid this issue?

Related

Need to "link" table cell editor with its table

I need to customise the selection behaviour of the cells inside a JTable descendant. I have a custom cell editor using a JTextField descendant as the editorComponent; there's a focus listener registered on it which manages the desired selection behaviour.
I need different behaviour when tabbing around the table than when another window or application comes to the front and then goes away again.
This is currently not possible, because the cell editor's editorComponent seems to have no off-the-shelf way of knowing (or telling it) that it's the editor for a table cell, so it doesn't know that it's "inside" the table, so my focusGained() and focusLost() think focus is moving between different windows even if I'm just tabbing around in the table.
SwingUtilities.windowForComponent() returns null for the editorComponent.
Before I roll my own solution, is there an accepted way of dealing with this issue? I can't be the first person to need to do this...

How to delete table row using jButton from another jFrame?

I am currently using FileWriter to write data into .txt tile.
Once I double click the row in the table, it links to another jFrame.
I wanted to set a button at the particular jFrame so that it is able to delete the row in the table. How can I perform the action?
Use the MVC (Model-View-Controller) paradigm.
Have a controller class, maybe containing the main method.
That holds the views (JFrame) and the data models (i.e. a DefaultTableModel).
That table model is passed to the table, which actually is also a listener to changes of the table model.
On button press let the button tell the controller that a row should be deleted.
This is done on the table model, and change events are fired. Automatically when using a DefaultTableModel. Or do it manually when using an AbstractTableModel.
MVC is not necessarily more direct, but there are not calls from one component to another components littered through the sources. It decouples things.
This can be done by adding a New button. Go into the codding of the button and add a simple sql statement saying to drop a row from the table And the another statement to show the table again by Select * from tablename;

Swing - How to add a JPopupMenu in a JTable Cell

I'd like to insert a JPopupMenu for each cell of a column of my JTable (to be able to select multiple items).
Any idea how to do that?
For multiple selections within a cell, you'll need both a custom renderer and editor. For the editor component, use a JList with the selection mode set to MULTIPLE_INTERVAL_SELECTION. The renderer should display something appropriate for the content, e.g. a comma-separated list of values. Note that the data for each row must be stored in the TableModel, not in the renderer and editor itself. The details will depend on your data model, but List<String> or EnumSet<String> may be appropriate.

Eclipse plugin - is TableViewer suitable when multiple tables required

I'm writing an Eclipse plugin for a screen definition editor. The preview page will have multiple tables of different rows/columns definitions, the contents of each cell is effectively a control definition (i.e. Label, TextBox, etc). Some basic requirements of the preview are:
User selection on any cell publishes the control properties to another view.
The cell styling is applied depending upon the control type.
Currently using JFace TableViewers but have the following issues:
1. Only one TableViewer can be registered as a selection provider via the getSite().setSelectionProvider(). How to listen for selection changes on all my tables?
2. TableViewer does not appear to allow for cell styling.
3. Cell selection programatically handling with a TableCursor, but the cell in a previous table is still highlighted when I select another cell in another table.
Are there more suitable layouts to use than TableViewer for my purposes?
Regarding point #2, cell styling, TableViewers do allow for customization of the display of cell data. Take a look here for some ideas on how to get started with that.
You can use this approach for supporting selection in multiple tables with some modification (add listener to each of your table viewers so if one of them is selected it automatically becomes the delegate).

how to add a jcheckbox when the table model initially is not defined.

how to add a jcheckbox when the table model initially is not defined.
I have populated the jtable with data from database, but now I need to add a jcheckbox used for selection of desired record.
I can add jcheckbox to jtable if the datatable rows are perdefined with boolean class. But as I am using a database to read from I am bit confused.
any help is welcome.
JTable relies on its TableModel to determine what to display. Although only existing rows can be shown, you can insert an uncommitted row in the model for editing. What and when to commit are entirely up to your application.
As discussed in How to Use Tables: Concepts: Editors and Renderers, the default renderer and editor for a column of type Boolean is a JCheckBox. Here's a simple example that conditions getColumnClass() accordingly. Here's a more complex example that defines a composite type, Value, as well as a custom renderer and editor.

Categories

Resources