Java,GridBagLayout

Java,GridBagLayout,java,swing,jlabel,imageicon,Java,Swing,Jlabel,Imageicon,嗨,我正在尝试调整图像图标的大小,我尝试使用getScaled方法,但它不起作用,我附上了下面代码的副本 public Example (){ JLabel l = new JLabel(new ImageIcon(getClass().getResource("gui/CheckLib.png"))); Image resize = l.getScaled(200, 180, 18); l.setIcon(new ImageIcon(resize

嗨,我正在尝试调整图像图标的大小,我尝试使用getScaled方法,但它不起作用,我附上了下面代码的副本

public Example (){
        JLabel l = new JLabel(new ImageIcon(getClass().getResource("gui/CheckLib.png")));
        Image resize = l.getScaled(200, 180, 18);
        l.setIcon(new ImageIcon(resize));

        setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.SOUTHEAST;
        c.weightx = 1;
        c.fill = GridBagConstraints.HORIZONTAL;
        add(l);

一些研究会告诉你,没有一个叫做
getScaled

更多的研究会让你

更多的研究可能会让你

这可能会导致你


现在请记住,将
java.awt.Image
包装在
图标
界面中

您可以试试Darryl的。它将根据图标的可用空间调整图像大小。

你说它不工作是什么意思?