#Making text-fields not user-editable
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
the text fields code:
double subTotal = (bagelsQuantity * bagelsPrice) + (cookiesQuantity * cookiesPrice)+ (muffinsQuantity * muffinsPrice) + (pieQuantity * piePrice);
textfieldSubtotal.setText(String.format("%.2f", subTotal)); // https://stackoverflow.com/questions/6350797/how-to-set-new-text-in-jtextfield-after-creation
final double taxRate = 0.13;
double taxAmount = subTotal * taxRate;
textfieldTax.setText(String.format("%.2f", taxAmount)); // https://stackoverflow.com/questions/34461275/how-to-set-text-format#:~:text=You%20should%20use%20the%20String.format%20%28%29%20method%20along,results%20that%20you%20want%3A%20high.setText%20%28String.format%20%28%22%2506d%22%2C%20gamescore%29%29%3B
double Gtotal = subTotal + taxAmount;
textfieldTotal.setText(String.format("%.2f", Gtotal));
textfieldTotal.setEditable(false);
I have a jTextField , and I set it's value to a certain sum when I create the frame.
Here is the initiation code:
totalTextField.setText(
itemsPriceTextField.getText() +
...
Not sure how I would make it unedible
uneditable*
Just call setEnabled() on it:
searchField = new JTextField();
searchField.setText("whatever");
searchField.setEnabled(false);
Detected code, here are some useful tools:
note that you might need to adjust colors to have black text instead of gray
Might aswell just use a label 😉
considerable difference in behaviour, I think I'd prefer textField when it comes to looks
looks don't really matter, stylesheet will override that
what stylesheet? JTextField is Swing iirc
You don't. The HTML parser that some Swing components use does not even support most HTML tags; it does not support CSS at all.
If you need advanced HTML support in a Java app, you will have to use one of the third-party components that provide it.
yeah , scroll down :p
looks are personal aswell. If its just for displaying some text that the user has no need to interact with, a label suffices
textbox screams, click me
Welll, I don't know about the use case of OP, but from what I saw you'll need to override UI LaF often enough anyways if you want custom behaviour - using CSS seems counterproductive to me
And labels on their own look kinda clunky, compare:
That's why I used textfield
I got it work so that if they click any button, they can no longer click on the textfield
But they can click on the text field before clicking any other button so it kinda worked and kinda didnt