我有一个用于JLabel的带有文本的图标,我正在尝试使文本垂直位于底部,但这是行不通的,这是我的整个课程:
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("my frame");
frame.setLayout(new FlowLayout());
JLabel label = new JLabel("my label");
ImageIcon mouse = new ImageIcon("mouse.jpg");
label.setIcon(mouse);
label.setVerticalTextPosition(SwingConstants.BOTTOM);
frame.add(label);
frame.setVisible(true);
frame.setSize(500, 500);
}
}
答案 0 :(得分:0)
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("my frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
JLabel label = new JLabel("my label");
ImageIcon mouse = new ImageIcon("mouse.jpeg");
label.setIcon(mouse);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
frame.add(label);
frame.setVisible(true);
frame.setSize(500, 500);
}
}