我在 a 中放置了两个组件,JLayeredPane但无法使它们可见。这是一个相当的MCV代码。我如何看到我的JTextField和JLabel里面的layeredPane?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
public class GUI extends JFrame {
JFrame mainframe = new JFrame();
JPanel centrejPanel = new JPanel();
JTextField keyText;
JLabel jLabel;
public GUI() {
mainframe.setLayout(new BorderLayout());
mainframe.setSize(1200, 700);
mainframe.getContentPane().add(centrejPanel, BorderLayout.CENTER);
keyText = new JTextField("hello");
keyText.setOpaque(false);
keyText.setCaretColor(Color.BLACK);
keyText.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
jLabel = new JLabel("hello");
jLabel.setFont(new Font("Palatino", Font.BOLD, 18));
jLabel.setVerticalAlignment(JLabel.TOP);
jLabel.setForeground(Color.GRAY);
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.add(keyText, 1);
layeredPane.add(jLabel, 0);
centrejPanel.getRootPane().add(layeredPane);
mainframe.setVisible(true);
}
}
public class Main {
public static void main(String[] args) {
GUI gui = new GUI();
}
}
拉丁的传说
相关分类