JTable, disable user column dragging - java

I have declared my JTable as:
data_table = new JTable(info, header) {
#Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
But I've seen that at runtime it's possible to drag the columns with mouse.
How can I disable that?

data_table.getTableHeader().setReorderingAllowed(false); should do the job, unless you mean that the user can resize column headers.

To anyone having this problem using Netbeans IDE you can disable the user from dragging columns in the JTable by doing the following steps.
Right click the table
Select Table contents
Click the columns tab
Uncheck the Allow to reorder columns by drag and drop

Related

Zkoss-8.5.1 Problem creating data binding programmatically

I'm creating a zk component for mount easy grid from view database. One of its powerful features is the automatic generation of filters by column. These filters appear automatically on the top column inside the auxheader tag and all are generated programmatically in java with the column info. Example of database view TIMESTAMP column (sorry not css right now):
https://prnt.sc/ZK9nMws2l68p
My problem now is that I don't know how to bind these datebox generated programmatically in java with the view for recovering the filter values.
I was searching inside the zkoss wiki and only found this:
create data binding programmatically,
where you can find how bind zk components of the zul, or how bind components generated programatically if the parent has an item render option.
But i need generate N datebox, numberbox, textbox depending on the number and type of the columns and recover the values of it.
Anyone knows how do it?
The component has a loot of code and scrap, but more or less the idea is:
https://pastebin.com/Q5VX472L
cols.setParent(gridDatatable);
// create filters inside AuxHeads
Auxhead auxhead1 = new Auxhead();
// create a line with the same number of AuxHeaders as Columns we have
for (int indexColumn = 0; indexColumn < columnsList
.size(); indexColumn++) {
if (columnsList.get(indexColumn).getVisible()) {
// i have definned the diferent Auxheader with a patron factory
Auxheader auxheader = gridDatatableFilterFactory.generateFilter(
columnsList.get(indexColumn).getTerms().getType(),
columnsList.get(indexColumn).getTerms().getKey());
auxheader.setParent(auxhead1);
}
}
// set the Auxhead line between col names and rows
auxhead1.setParent(gridDatatable);
// we add the rowrender for print the rows
gridDatatable.setRowRenderer(
new DatatableRowRender(columnsList, gridDatatableCellFactory));
search();
Thank you in advance, regards.

nattable multiple row selection

I am using NatTable and I want to select some rows in my table. Additional I want to select some other rows after this (CTRL + left mouse-click).
There is no problem with the first selection, but when I try to select some additional rows, my first selection got lost. This happens only if I do my second selection in dragmode. When I select every additional row by single clicking everything works fine.
I used the RowSelectionModel with the DefaultRowSelectionLayerConfiguration:
selectionLayer.setSelectionModel(new RowSelectionModel<Entry>(selectionLayer, bodyDataProvider, new IRowIdAccessor<Entry>() {
#Override
public Serializable getRowId(Entry rowObject) {
return rowObject.getStartLine();
}
}));
selectionLayer.addConfiguration(new DefaultRowSelectionLayerConfiguration());
Maybe I just did a silly mistake and you guys can help me.
It looks like an issue in the NatTable code. I created a ticket for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=494392

Java SWT TreeViewer with one column that needs to be StyledText

I have a TreeViewer used in an eclipse plugin that uses a content provider and a label provider that implements all of (ITableLabelProvider, IFontProvider, IColorProvider).
But I need one of the columns of the table it creates to hold "links" - underlined blue text that when clicked causes some popup to open. I guess what I want to do is cause that single column to hold styled text and not just text, and attach a listener to the items in that column of the tree, but I couldn't figure out how to do it.
Use a separate label provider for each column using TreeViewerColumn:
TreeViewer viewer = new TreeViewer(.....);
TreeViewerColumn col1 = new TreeViewerColumn(viewer, SWT.LEAD);
col1.setLabelProvider(col1 label provider);
... repeat for other columns
For columns that require styling use DelegatingStyledCellLabelProvider as the column label provider as described here
Note: Do not call viewer.setLabelProvider when using column label providers.

How to remove item in JTable also remove from Database?

I am pretty basic to link from Java to Database.
I link item from Database (I use MS.Access) to Java table (JTable)
but when I delete in JTable using this code
int numRows = tblweng.getSelectedRows().length;
for(int i=0; i<numRows ; i++ )
((DefaultTableModel)tblweng.getModel()).removeRow(tblweng.getSelectedRow());
it deletes only in Table but not in Database. So how I can remove both of them at the same time I click "Remove Button".
Please guide me but don't go too deep I am just a basic here. Thank in advance.
1. click Jtable // row selected
2. get data form dep_Table like
int a = dep_Table.getSelectedRow();
String b = String.valueOf(dep_Table.getValueAt(a, 1));
3. What data you want in you get and store in String
4. Connect Database
5. use Delete Query and Delete Data From Database
6. Reload Table Again
These Few basic Step is Enough for You.. I Think..

SmartGWT ListGrid - exclude field from selection

I would like to ask for your help to solve the following problem.
I have a SmartGwt ListGrid wich has multiple rows in it.
This ListGrid has a SelectionChangedHandler which works just fine.
I added a special column (ListGridField) to this ListGrid, on which basically I want to prevent the selectionChangeEvent to trigger when clicked.
This special column has its own recordclickHandler.
I only want to EXCLUDE this column form changing the selected record in the ListGrid.
Is there any way to do so in your knowledge?
Thanks in advance.
Since the event for row selection doesn't tell you which cell you clicked on, hence no way of telling which column, I think you'll need to make cells selectable, and ignore the event if the cell is in the excluded column.
myGrid.setCanSelectCells(true);
myGrid.addCellSelectionChangedHandler(new CellSelectionChangedHandler() {
public void onCellSelectionChanged(CellSelectionChangedEvent event) {
CellSelection selection = countryGrid.getCellSelection();
//use to determine if excluded column is clicked:
int[][] selectedCells = selection.getSelectedCells();
//use to get selected row:
ListGridRecord record = selection.getSelectedRecord();
//etc...
}
}

Categories