开发者

java gui builder custom jlabel

开发者 https://www.devze.com 2023-02-09 00:43 出处:网络
How do I add a custom JLabel in Netbeans\' 开发者_Go百科gui builder?If you\'re just looking to see how to create JLabel\'s dynamically, you\'re close, although the snippet of code you posted in a comm

How do I add a custom JLabel in Netbeans' 开发者_Go百科gui builder?


If you're just looking to see how to create JLabel's dynamically, you're close, although the snippet of code you posted in a comment has several errors in it. Here's a similar example to your code:

import javax.swing.*;

public class Jpl extends JPanel {
    public static final String[] LABEL_TEXT = {"Monday", "Tuesday", 
        "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

    public Jpl() {
        for (int i = 0; i < LABEL_TEXT.length; i++) {
            JLabel lbl = new JLabel();
            lbl.setText(LABEL_TEXT[i]);
            add(lbl);
        }
    }

    private static void createAndShowUI() {
        JFrame frame = new JFrame("Jpl");
        frame.getContentPane().add(new Jpl());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                createAndShowUI();
            }
        });
    }
}

If on the other hand, you're trying to create your own class that extends from JLabel that you can put in the NetBeans GUI-builder palette, then things will be a bit more difficult.

edit: but not impossible. Custom components can be added via NetBeans Palette Manager. For more on this, please check this link: Creating GUIs with NetBeans Check the section on Custom Components

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号