Positioning JLabel in JPanel below the image

后端 未结 1 1659
悲&欢浪女
悲&欢浪女 2021-01-25 00:07

I want to move the Text below the image and shape in the given example. Please help me to do it.

    package test;

    import java.awt.BasicStroke;
    import          


        
相关标签:
1条回答
  • 2021-01-25 01:02

    Consider making use of the API's available functionality...

    Take a look at:

    • JLabel#setHorizontalTextPosition
    • JLabel#setVerticalTextPosition
    • How to use labels

    For example...

    private ImageIcon image;
    
    public TestLabel100(Integer size, String name) {
        //...
        JLabel textLabel = new JLabel(name);
        textLabel.setIcon(image);
        textLabel.setHorizontalTextPosition(JLabel.CENTER);
        textLabel.setVerticalTextPosition(JLabel.SOUTH);        
        //textLabel.setBounds(100, 100, 70, 30);
        //...
    }
    
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        //...
    
    0 讨论(0)
提交回复
热议问题