I'm trying to make a small app with the following look
2d3a438a99c57975b0cd40c49d67c502

Thats an edited image of what exactly im trying to achieve. But here's what I got...

b7f011c0afa0031328e917e8553abc2d

Could you tell me where I went wrong. And if it isn't much effort could you advise on how I can write the extra labels and bottom buttons properly.

Here's the code I used. Somehow the image gets cut :(

public MusicBox(JFrame frame) {
        super(new BorderLayout());
        this.frame = frame;

        // Logo scaled and fit
        ImageIcon logo = createImageIcon("logo.png");
        BufferedImage bi = new BufferedImage(logo.getIconWidth(),logo.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bi.createGraphics();
        g.scale(0.5,0.5);
        logo.paintIcon(null,g,0,0);
        g.dispose();

        JLabel imgLabel = new JLabel();
        imgLabel.setIcon(new ImageIcon(bi));
        //JPanel panel = createGUI();
        status = new JLabel("Initializing..",JLabel.CENTER);

        add(title,BorderLayout.PAGE_START);
        imgLabel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        add(imgLabel,BorderLayout.CENTER);
        imgLabel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        add(status, BorderLayout.PAGE_END);
        status.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

    }
  • in Swing are implemented methods for displaying Icon / ImageIcon in JComponents APIs

  • put ImageIcon / Icon (create an loval variable) to the JLabel.setIcon(logo) directly,

  • for this job isn't required to play BufferedImage

  • another issue is about layout contens properly

I not sure that your resizing method will correctly get the size in the final result. Use getScaledInstance to resize an Image safely.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.