Reputation: 19787
In order to solve a problem I am currently working on, I need to find out what is the default height of a JLabel. I am using a dummy approach:
JLabel label = new JLabel();
Dimension dim = label.getPreferredSize();
Is there a way to get the default height without instantiating JLabel?
Upvotes: 1
Views: 457
Reputation: 109815
I need to find out what is the default height of a JLabel. I am using a dummy approach:
JLabel label = new JLabel();
Dimension dim = label.getPreferredSize();
is possible but you have to accept that this is done by LayoutManager, then there are two options
Swing/AWT GUi is already visible on the screen
after JFrame.pack() is called
(I don't suggest, just for wroting a complete answer) is possible to get getPreferredSize for most of JComponents by using/invoke
NullLayout by using Insets
revalidate() and repaint() in already visible Swing/AWT GUI
Is there a way to get the default height without instantiating JLabel?
Upvotes: 3