0

まず第一に、私はレイアウト マネージャーの存在をよく知っていますが、この場合は使用したくありません。

アプリケーションの簡単なメイン メニューを作成していますが、何をしても Image ( JLabel) は常に画面の左上隅に設定されます。両方の方法 ( setLocationsetBounds) を使用してみましたが、違いはありません。

ばかげた間違いだと確信していますが、それを理解できないようです。

これが私のコードです:

import javax.swing.*;

public class Main extends JFrame{

    protected ImageIcon createImageIcon(String path,
                                        String description) {
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    Main() {
        ImageIcon image1=createImageIcon("/monopoly.jpg","");
        JLabel image1l=new JLabel(image1);
        image1l.setLocation(200,200);
        image1l.setBounds(330, 300, 140, 60);
        add(image1l);
    }

    public static void main(String[] args) {
        Main f=new Main();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        f.pack();
        f.setTitle("Monopoly");
        f.setSize(800,800);
        f.setLocationRelativeTo(null);
        f.setLayout(null);
    }
}
4

0 に答える 0