我正在用Java编写程序而我使用JPanel
用于the
界面,但我遇到问题总是在顶部,我不想要这个。我希望当我恢复另一个窗口时,它将位于顶部。
我尝试过:
this.setAlwaysOnTop(false);
但它不起作用,框架始终在最顶层。
这是一个简单的程序,我的问题是:
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BorrarRegistro extends JPanel
{
public BorrarRegistro () {
super(new BorderLayout());
JLabel insertar= new JLabel("Registro");
JTextField borrar= new JTextField();
JButton borrar1= new JButton("Borrar Registro");
JPanel borrarRegistro= new JPanel(new GridLayout(4,1));
borrarRegistro.add(insertar);
borrarRegistro.add(borrar);
borrarRegistro.add(borrar1);
JPanel images= new JPanel(new GridLayout(1,3));
add(images,BorderLayout.NORTH);
add(borrarRegistro, BorderLayout.SOUTH);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ClaseBase ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
BorrarRegistro newContentPane = new BorrarRegistro ();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
// Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(
new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
如何解决此问题?
答案 0 :(得分:3)
您应该在创建框架时调用setAlwaysOnTop(false)
。
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ClaseBase ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
Test newContentPane = new Test();
newContentPane.setOpaque(true); //con
frame.setContentPane(newContentPane);// tent panes must be opaque
frame.setAlwaysOnTop(false);
// Display the window.
frame.pack();
frame.setVisible(true);
}