I have a JLabel for an error output. This is empty in the beginning and can be filled by some actions. But when it's empty it won't be noticed when I pack() my JFrame. So when my error label gets content, I need to repack my frame to make it visible (and that also resizes the frame what I want to avoid).
At the moment I use
lError.settext(" "); // set text to space as buffer content
but I'm not happy with this solution.
Is there another cleaner way to reach my result?
Edit: I reached what I wanted by editing the size of the panel around my label with setPreferredSize()
, but I still have this space buffer.
pError.setPreferredSize(new Dimension(pError.getPreferredSize().width, new JLabel(" ").getPreferredSize().height));