Forums Register Login

Refresh

+Pie Number of slices to send: Send
I've got my beautiful gui program all done except for one thing. How would I go about changing the text in a JLabel? jLabel.setText("whatever") changes the text I know, but it doesn't actually show the change. What do I do???
+Pie Number of slices to send: Send
jLabel.repaint();
+Pie Number of slices to send: Send
doesn't work

I've got the label a few panels deep, so I don't know if that's affecting it or not. I even tried repainting everything in the whole tree leading down to the labels.
+Pie Number of slices to send: Send
Depends on how you put things together. If the new text changes the size of the JLabel you may need to call revalidate on the label.
+Pie Number of slices to send: Send
Something that always works for me is:

invalidate()
validate()
repaint()

Sort of covers all of your bases. Hope that helps.

Normally, I would expect the JLabel to repaint itself when you call setText() so its surprising that you are having that problem actually...
+Pie Number of slices to send: Send
None of that's working. I'll post my code for someone to look at, but it's lengthy so I'll only do it if it's asked for.
+Pie Number of slices to send: Send
>I'll post my code for someone to look at, but it's lengthy so I'll only do it if it's asked for.

post just enough (compilable) code to demonstrate the problem.

just a thought, you don't have a duplicate declaration, something like this -
run it as is, no change, comment out the duplicate declaration and it changes

+Pie Number of slices to send: Send
Good idea, but that's no it either. The labels only have one instance of each. I have each of them inside an inner class extending JPanel, and those panels are in the JFrame.
+Pie Number of slices to send: Send
Thanks to those who helped, I found the bug. I wasn't resetting the text; I was reinstancing the labels. Dumb mistake.
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1471 times.
Similar Threads
printing on an applet
More Reverse2Servlet
how to string search ?
I have a doubt
File constructor
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:42:33.