#How can I convert a String into a JLabel?
30 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @vagrant veldt! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
you can't however the constructor JLabel(String) accepts a String that will be displayed as the text of the JLabel
ok but thats not what I wont I want to save and load the hole JLabel
Is there any other way?
from a file ?
you are just printing the output of the toString() method to the file, aren't you ?
no I write the JLabel dirctly in it
how exactly ?
yeah that's what I meant. Have a look at ObjectInputStream and ObjectOutputStream if you are trying to store and load the entire state of the object. This is pretty easy to implement since JLabel implements the Serializable interface. Otherwise you may also find it beneficial to write your own save/load mechanism if you only need certain properties.
How exactly?
Why is there no file?
because you referenced a folder
Hä?
where do you mean?
wait I have it
Now I juse Input and Outputstream and how can I store the data in the variables when I read?
this might be more helpful: https://www.baeldung.com/java-serialization
all my variables are static
you don't need to serialise your class. You need to serialse the labels.
Is there no other way to save a JLabel and load it?
you have always the option to write your own save/load method