简体   繁体   中英

How can I set the vertical/horizontal height of a JLabel? (Netbeans)

When I click a JButton , I want a new Jlabel to be created and to appear on a position on the GUI of my choice. Note that I am using the GUI builder in Netbeans, meaning it auto-generates the code for GUI components.

I tried seeing what the auto-generated code does when creating a label but it didn't work.

Is there any way to do this?

Without giving us any code the thing that should have more chance to work for you is the following:

Add the label from the builder with the regular way. Exactly as you added the other components. Switch to code and you will see somewhere like

JLabel label = new JLabel("some text");

Just right below this line make the label invisible (after it is being declared).

label.setVisible(false);

Now the label is there, in the position you want it. Now the only that is left is to show it - make it visible when the button is pressed. So...

button.addActionListener(e -> label.setVisible(true));

Graphically it should be appearing like this, then you can modify the label with the mouse, keep in mind if you want you can change font and size of font, it helps to increase the size of label as well

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM