Dynamically change the width of JDialog
I have created a JDialog which contains a JLabel. Because the length of text, which changes based on users' input, can contain a large number of characters, there is the need to dynamically change the length of the JDialog based on the size of length of the JDialog. I have tried the pack() method but it's not the case for it. Can anyone give me some tips? Thanks in advance! mKorbel getPreferredSize for JLabel - basically you have to get textLength from JLabel in pixels, there are 3 correct ways, but I love: SwingUtilities.computeStringWidth(FontMetrics fm, String str) Now you are able to