JTable headers on left side and cells on right [explained with image] - java

As second picture says, I want to anchor 'HeaderModel' left and 'CellModel' right. If its possible...

A JTable will display whatever data is returned by the getValueAt() method. You can change a cell's appearance using a suitable renderer. You can obtain a copy of the default header renderer, as shown here. This complete example shows how to apply the renderer to the table's first column.

Related

Select only column header and no row in an SWT table after click on column header

I have an Eclipse SWT table. It contains multiple rows (with row headers) and multiple columns (with column headers). On click on a column header I want to deselect all rows and highlight only the column's header (or all cells of this column). Is that possible?
I already registered a listener for the column header's selection and am able to set the selection to the given column, but then it also always selects the first row automatically. I tried with SWT.FULL_SELECTION and SWT.SINGLE as the style of my table, but it only changes the way how the row is highlighted, but I want only to highlight the column's header (or optionally all cells of this column) and no rows.
Is it possible? Did anyone have the same problem?
I ran into the same problem and I'm afraid you can't do that in SWT.
I solved by imitating the selection of a column; I colored the cells as if they were selected, and dropped the "real" selection.
You should extend your own TableViewer and override the getSelection() method to reflect that you now also have this imitated kind of selection.
(And from a UX perspective, you should make sure that a copy command (i.e. Ctrl+C) behaves as users expect it.)

How would a dev make a JTable LOOK editable

I'm writing an application that has a JTable, and an edit button that sets the current selected row to be editable. Then once the user is done altering the data, they can click the edit button again (with text that now says "Save") to save the data.
The problem is though, when I set a row to be editable, there isn't a visible difference. I could add some code to the renderer to draw the editable cells a little differently, but I don't know what the proper way to make a cell look editable is. Change the color? Make it look like a JTextField? What's the standard method?
Thanks!
Really this is a user interface design question, not a programming one.
To do what you want you need to supply an appropriate cell renderer with the changes you desire but you will need to decide on your own settings. One option might just be to look at the difference between an editable and non-editable text area and apply those to all the cells on the table. This may be as simple as setting the renderers to disabled for any read-only rows.

JXTable and Header Cell Above Scrollbar

JTable and JXTables have a header cell that is generated above the scrollbar. It's a small cell but I would like to use it to render an icon and popup menu. How might I access this header cell?
Thanks
In JXTable, the property to set is the columnControl: basically, it can be any component you like. To keep the functionality of the default, you can subclass ColumnControlButton

Multiline feature in an editable jtable cell

I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell. Would be very thankful.
Thanks in advance.
Several steps:
implement a custom renderer using a JTextArea as rendering component
implement a custom editor using a JTextArea inside a JScrollPane as editing component
add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification

Make header text bold when its column is selected in JTable

is possible to turn header text bold when I select a cell of its column? How to do it?
Thanks
Leandro
Set custom renderer into table header. If current column is selected column set font to bold.
JTable table = new JTable()
table.getTableHeader().setDefaultRenderer(new MyRenderer());
class MyRenderer implements TableCellRenderer {
//todo implement
}
It is partially possible. What you have to do is write your model is such way that on table's cell selection your model executes fireTableStructureChanges method( assuming you use AbstractTableModel as a base). This will repaint the whole table including column header. All you have to do is keep the state of which column is selected.
In the beginning I said "partially" possible. That is because calling fireTableStructureChanges will revalidate the whole table and you will lose your current column model state - column widths and sequence.
To make your text bold you can use HTML - something like <html><b>your text</b></html>, but it has to change dynamically based on your model's internal state
UPDATE: Also column table header text can be set directly but model change or tableStructureChanged event will make the table to reread from the model.

Categories

Resources