基本的に背景( Paint() を使用してペイントされる)を持つプログラムを作成し、その上に画像を含むラベルを配置しようとしています。
ペイントの下に JLabel を取得し続けます...
何か案は?
よろしくお願いします。
public class GUI extends JFrame {
JPanel menuBar = new JPanel();
JButton button1 = new JButton("Press Me");
JLayeredPane layeredPane = new JLayeredPane();
private ImageIcon image1;
private static JLabel label1;
public GUI() {
super("Add a profile");
setLayout(null);
try {
image1 = new ImageIcon(getClass().getResource(
"Images/location.PNG"));
} catch (Exception e) {
System.out.println("Image not found!");
}
label1 = new JLabel(image1);
label1.setBounds(new Rectangle(new Point(262, 94), label1.getPreferredSize()));
label1.setLocation(1, 1);
label1.setSize(114, 105);
add(label1);
}
public void paint(Graphics g) {
paintComponents(g);
Graphics2D g2d = (Graphics2D) g;
// Menu Bar
g2d.setColor(Color.BLACK);
g2d.drawRect(60, 93, 190, 373);
g2d.setColor(Color.GRAY);
g2d.fillRect(61, 94, 189, 372);
// Background box
g2d.setColor(Color.BLACK);
g2d.drawRect(281, 106, 560, 360);
g2d.setColor(Color.GRAY);
g2d.fillRect(282, 107, 559, 359);
}
public static void main(String[] args) {
GUI gui = new GUI();
gui.setVisible(true);
gui.setSize(900, 550);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setResizable(false);
gui.setLocationRelativeTo(null);
}
}
悲しいことに、それを機能させることはできません。とにかくたくさんありがとう ごめん!今から見てみます
本当に感謝しています!