I add the column value of JTable to JComBoBox full of null notifications
I tried passing the sub-variable and then adding jcombobox but it was not
I have test two ways but failed
1.TableColumn testColumn = tbclass.getColumnModel().getColumn(1);
testColumn.setCellEditor(new DefaultCellEditor(jcombobox));
2.tbclass.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcombobox));
The error is
java.lang.NullPointerExceptionat
Related
My program should translate the pairs of key/value of a table to a escaped JSON for shell execution. This JTable is inside a JSplitPane, but only 4 rows are displayed and when there is less than 4 a white background appears where the other 1-3 rows should be. (There are more than 4 registers)
e.g.:
With data:
Without data:
As you can see the JSON on the bottom has all the table data, but the JTable is not rendering it right. Table filling code:
DefaultTableModel dtm = ((DefaultTableModel) tblParameters.getModel());
dtm.setRowCount(0);
currentFileParameters = (ReplacerLinkedHashMap<String, String>) FileParametersDAO.getInstance().getParametersForFile(file); // get parameters from database for specific file
for (Map.Entry<String, String> entry : currentFileParameters.entrySet()) {
dtm.addRow(new Object[]{entry.getKey(), entry.getValue()}); // add row
}
dtm.addRow(new Object[]{"", ""}); // add blank row for adding more parameters
tblParameters.revalidate(); // failure trying to resolve the problem [part 1]
tblParameters.repaint(); // failure trying to resolve the problem [part 2]
LocalProperties.setLastAccessedFile(file); // saves the accessed file
loadSavedFiles(); // load all saved files to other table (that has the same problem)
Table was working before and stopped suddenly. Thank you in advance.
I am designing a Java project which contains a Radio button group having 15 jRadio buttons. Each Radio button have names like "Master", "Front_desk", "Accounts" etc. and this text name is defined in MySQL table. In MySQL table I have defined whether to enable or disable particular radio button. I use following code to get Radio button name from MySQL table
String Btn_name = Rs.getString("Module_name");
after get Btn_name I tried to enable or disable the radio button state by using follwing command
Btn_name.setEnabled(true);
or
Btn_name.setEnabled(false);
but I am getting following error
can not find symbol
symbol : method setEnabled(boolean)
location : variable Btn_name of type String
You need to create a jradiobutton in a standard way,
JRadioButton btn = new JRadioButton().
btn.setText(Btn_name);
btn.setEnabled(true/false);
And create as many jradiobutton you need in a loop over the resultSet.
I created JTable, using Design View - Table.
But, I want the values to come from SQL query, not to be inserted manulally.
So I select on table: model -> Custom Code, then there is: jTable1.setModel();
What I can put there? I tried with methods to return value, but NetBeans tell me, String cannot to be converted to TableModel.
I can't modify the code initComponents(), which is generated from NetBeans, I can only put method there.
So how to get values from SQL or what I can use here setModel() to retrieve the result from SQL.
Table: 3 columns x 7 lines
The code:
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(resultsTable());
jTable1.setToolTipText("");
jScrollPane1.setViewportView(jTable1);
... more code for the frame .....
You could also make your table model by extending AbstractTableModel class and overriding appropriate methods.
Take a look at this https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data
I found very easy solution:
https://www.youtube.com/watch?v=fbYxThOFsLI
This is exactly what I want, using Table, generated from NetBeans.
Thanks to everyone!
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.
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...
}
}