如何调整图像在Java上的位置?

问题描述

我正在尝试调整图像在弹出Java窗口中的位置,但无法弄清楚如何(我正在使用Buffered Image和JLabel将其添加到弹出窗口中)。

import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class CustomPanel extends JPanel
{
  private JButton Eyetoggle;
  private JLabel label;

  public CustomPanel()
  {
    super();
    Eyetoggle = new JButton("Toggle Eyes");
    ImageIcon icon = new ImageIcon("/Users/toprakbirben/Desktop/body.png");
    label = new JLabel(icon);
    setupPanel();
  }

  private void setupPanel()
  {
    this.setBackground(Color.CYAN);
    this.add(Eyetoggle);
    this.add(label);

  }

}

我使用JFrame为我的项目创建框架


public class Outline extends JFrame {

private CustomPanel appPanel;
  
  public Outline()
  {
    super();
    appPanel = new CustomPanel();
    setupFrame();
  }

  private void setupFrame()
  {
    this.setContentPane(appPanel);
    this.setSize(800,800);
    this.setTitle("Potato Project");
    this.setVisible(true);
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)