Hide the text that inside the text field - java

how to hide the text inside the text field?
I'm using the radio button and group with 2 selection(A and B).
For example, when i choose A, the text inside textfield B will hidden. When choose B, the text inside textfield A will hidden and textfield B will appear.
jtfLTCurrentTransferLimit.setVisible(true);
jtfLTCurrentWithdrawLimit.setVisible(false);
i using .setVisible to archive this. But the textfield will gone when i clicked.
Any solution?

You could save the text of the hidden field into a String field and then set that hidden field's value to "". Then you can restore that value later when it becomes unhidden. You may also want to disable the hidden field, as suggested by the other answer, to prevent editing.

You could setEnabled(false) and then set the foreground and background colour of the text to the same colour.

Related

JavaFX set listview to be editable

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.

Collection in java that can disappear in scene builder

I am making a collection of button and text field in java. Whenever one of the button is pressed, i want to make the collection invisible/disappear. Is it possible? What collection should i use?
All the buttons and text fields whom you want to make invisible ,keep inside a JPanel. Now when the desired button is pressed you want to make jpanel.setvisible(false).
Write this code inside the ActionListener of that particular button

Ghost text in jTextField swing

Have a problem with GUI.
How to add text in jTextFiled that will disappear when I click on this field?
Have no idea how to realize this. jTextField has only one field for this property.
Thank you!
You can use the Text Prompt class which adds this functionality to any text field.
You have a property to control when the prompt is displayed.
The class basically adds a child (JLabel) to the text field which is painted when the text field doesn't have any text.

java - how can i edit the form's height/width (I use Netbeans)

I try to create a simple program where, from click a button i could size by height?
Ex. :i create a text field, a button. If In a text field i write 255, form's height of the form expands by 255.
Thanks
Shouldn't be that hard, right? Add an ActionListener to the button, and when the button is clicked, retrieve the integer from the textfield and use it to set the form's height/width.

JTable cell value passed to textarea on single click

On my form I have a jtable and a textarea. My table only has 2 columns - ID and Comment
Is it possible that when a user clicks on a cell in the comment column. The cell value will appear in the textarea in edit mode?
I did set the cell editor to singleclick
selectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn col = selectTable.getColumnModel().getColumn(1);
DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField());
singleclick.setClickCountToStart(1);
col.setCellEditor(singleclick);
I have a method outputSelection() that gets called from a edit button. The method gets the value from the selected cell and puts the value in the textarea for edit.
Can the click activate the method so the user does not have to click a edit button?
You could attach a mouse listener to the table and monitor the mouse clics from there, getting the selected column/row & thus the value
You could supply your own cell editor that updates the text area when the editors value is set
You could extend te jtable & when cell editing is started, update the text area
Yes, this is a process I learned to use after having duplicate code throughout my swing application. I started making standalone methods that did the work I wanted, and then I call those methods from the action events from the button or mouse click. That way they all execute the same code.
Even if you have a tab or enter key command, you can also have it execute your same method as the others for more consistent code.
If your button performs specific code with cell values, just extract all of that code out into a method that takes the cell value as input. Then you can call that same method from any event and pass in the input data you want to display in the text area.

Categories