JavaFX set listview to be editable - java

I am kinda new to JavaFX, so maybe this is very easy to do. I have a ListView<String>, and what I want is that I can have a button which when pressed, basically turns the selected String into a sort of text field in which you can edit the name of that specific item. I hope it is clear what I want. I already tried list.setEditable(true), but that didn't change anything.

In addition to making the ListView editable you also need to make sure to use a cellFactory providing editable cells:
list.setEditable(true);
list.setCellFactory(TextFieldListCell.forListView());
This way you can start a edit on a double click of a cell.

First, I'd use in this case a VBox filled with the TextFields. Those TextFields should have the editable property set to false. When you click on the button, you can call:
((TextField)vbox.getChildren().get(numberofTextFieldInList)).setEditable(true);
and now it should be editable. If you want the TextFields to look like Strings when not being editable, I would modify the aesthetic properties.

Related

Use JTable entries as buttons

I have a JTable which contains names returned from a search in database. I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder. Can I do that ?
This is easy to do, add the mouse listener to the table and use columnAtPoint and rowAtPoint to determine what has been clicked.
If you want a table cell to look like a button, set a renderer that uses JButton.
I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder.
You need to create a custom renderer and editor for your table. Read the section from the Swing tutorial on Concepts: Editors and Renderers for basic information.
Then you can check out Table Button Column which is an example of a render/editor that you can use. You will need to provide your own custom Action to display the details.

How do I allow selection of text in a cell using the right click button, but default behavior on left?

I am currently modifying the behavior of a JTable. My final goal is to allow selection of text in a cell, without making the cell editable through the use of the mouse right click. Everything should remain the same on hover, or when using the left click.
I am having trouble however when trying to do this. I have messed with non-editable text fields as cell editors, carets, and etc. but I can't seem to achieve the result I want.
Some resources I looked at include:
http://www.coderanch.com/t/332800/GUI/java/JTable-highlight-text-cell
Highlighting the text of a jtable cell
How to make a cell behave like it's editable but have it read only?
etc.
None of them have helped in my current predicament.

Using Button Groups to Make Checkboxes Unselectables

I have checkboxes. I have a buttongroup. When I click on the option "All Checkboxes," I want all checkboxes in the button group to be made unselectable (grayed out) (Except the "All Checkboxes" one which is selected.) How do I this?
Also, how can I add an item/set the items to a Combo Box using NetBeans?
I have checkboxes. I have a buttongroup. When I click on the option "All Checkboxes," I want all checkboxes in the button group to be made unselectable (grayed out) (Except the "All Checkboxes" one which is selected.) How do I this?
A ButtonGroup cannot be used to grey-out (functionally and visibly disable) a JCheckBox. Better to put them in a List<JCheckBox> and in the ActionListener for "All CheckBoxes" iterate through calling setEnabled(true/false) on the items in the list, the parameter depending on the state of the "All Checkboxes" JCheckBox.
Also, how can I add an item/set the items to a Combo Box using NetBeans?
I have no idea how to do this "using NetBeans", but using Swing you simply get the JComboBox's model, usually a DefaultComboBoxModel, and add items to it.
Also, how can I add an item/set the items to a Combo Box using NetBeans?
Just like you would with Swing normally, comboBox.setModel(comboBoxModel). Don't rely on the form editor to do it for you. Somethings you just have to get your hands dirty with.

Problem in obtaining the focus of JTable?

This is the scenario:
I have a JTable of nxn. In the Col(0) of each cell, have a slider with two thumbs each for min and max,two JTextField to represent min and max.
Whenever i click for first time on the cell, slider doesn't responds but on the second click the slider responds.
My guess is that on the first click the JTable gets the focus and on the second click the cell.
would like the cell to respond on the first click.
Thank you on advance...
set setClickCountToStart(1), more descriptions here
As I didn't see your code, I guess it's the FocusTraTraversalPolicy that is causing your problem.
In each container of Swing, the components have a predefined order of getting focus. They get the focus in order when you press the Tab button on the keyboard. So when you first click a container, there's a default component that gets the focus, if you're not satisfied with it, you can use the FocusTraversalPolicy to modify it.
Check this lnk out, it may help you.

How do I "combine" JButton with JComboBox?

How do I "combine" JButton with JComboBox and place it on a JToolbar, as shown in this image:
?
You'll want to use a custom renderer I suspect, and have it display clickable buttons (with the appropriate actions attached, etc).
Just create regular combo box and put image as an item. I did it once. Unfortunately I do not have a source code here but as far as I remember it was not a problem. You have to implement your custom 1ListCellRenderer. Its methodgetListCellRendererComponent()` should return for example Label with your image.

Categories