JLabel text disappears in JPanel after resizing

I have two visualization tools. One of them extends JTextArea, and the other inherits JPanel. I add them to another JPanel with a GridBagLayout.

When resizing JTextArea, I see at least some text. In the case of JPanel, I have two labels, and if the JPanel is small, they completely disappear.

Is it possible to resize JLabel instead of fading?


Thank you for your responses!

Using BoxLayout for JPanel and defining minimum, preferred, and maximum sizes helped solve my problem.

+4
source share
2 answers

Have you tried using the setMinimumSize(Dimension) frame?

 frame.setMinimumSize(new Dimension(100, 100)); 

A look at the documentation tells me that the behavior you see is platform dependent, so if you have multiple platforms, it might be a good idea to check the code that you have on each of them; which ones work and which don't.

The following code example works for me as desired in Windows Vista:

 import javax.swing.JFrame; import java.awt.Dimension; public class Ex extends JFrame { public static void main(String[] args) { JFrame frame = new JFrame("YOU CAN'T SHRINK ME COMPLETELY!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setMinimumSize(new Dimension(100, 100)); frame.setVisible(true); } } 
+1
source

check panel layout manager.

-2
source

Source: https://habr.com/ru/post/1390644/


All Articles