Мой ожидаемый результат: для изображения «crown.jpg», а также текста «Привет, Адам!» появиться в кадре. Однако отображается только текст.
Вот мой код:
Код: Выделить всё
package firstfxjava;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main {
public static void main(String[] args) {
// JFrame = a GUI window to add components to
// JLabel = a GUI display area for a string of text, an image, or both
ImageIcon image = new ImageIcon("crown.jpg"); //creates an ImageIcon
JLabel label = new JLabel(); // creates a lable
label.setText("Hi Adam!"); //sets text of lable
label.setIcon(image);
JFrame frame = new JFrame(); //creates a frame
frame.setTitle("JFrame title goes here"); //sets title of frame
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //exit out of application frame
frame.setSize(420,420); //sets the x-dimension, and y-dimension of frame
frame.setVisible(true); //make frame visible
frame.add(label);
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ame-vscode
Мобильная версия