[英]JLayeredPane for Java
我目前的問題是我有一個JFrame(上面有一些按鈕)...當我單擊“ New”按鈕時,它將在屏幕上調用一個InternalFrame ...內部框架屏幕出來了,一切都很好直到我移動內部框架,發現它位於所有部件的背面...
我已經嘗試過.toFront(),.setAlwaysOnTop()以及其他所有方法...直到遇到JLayeredPane為止,我認為這是我正在尋找的東西...但我無法使其正常工作> <引導我通過它嗎? 謝謝!
請務必告訴您所有您需要的額外信息。將盡快為您提供
WindowConstruct wconstruct;
JDesktopPane desktop = new JDesktopPane();
JInternalFrame InternalWindows = new JInternalFrame();
public MainUser(){
wconstruct = new WindowConstruct("..:: User's Helpdesk Main Page ::..", 1500, 800, false, null, "user");
wconstruct.add(desktop);
wconstruct.btnNew.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if(src == wconstruct.btnNew){
InternalWindows.setSize(500, 300);
InternalWindows.setTitle("New task");
InternalWindows.setLayout(null);
InternalWindows.setLocation(100,50);
InternalWindows.setClosable(true);
desktop.add(InternalWindows);
InternalWindows.setVisible(true);
}
}
我似乎沒有任何異常,嘗試使用您顯示的代碼創建MCVE。 這不是最好的代碼,但是我試圖盡可能地保持代碼的外觀。 查看一下,讓我知道我的代碼有何不同。 同樣,為了更好地幫助我們深入了解問題的根源,您應該始終發布MCVE。 這意味着代碼應該是可運行的,即復制,粘貼,編譯,運行。
並且還請考慮我上面所有的注釋(例如,如果您不打算使該應用程序成為MDI(請參見注釋中的鏈接)類型的應用程序,則可以使用JDialog。
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
public class MainUser implements ActionListener {
WindowConstruct wconstruct;
JDesktopPane desktop = new JDesktopPane();
JInternalFrame InternalWindows = new JInternalFrame();
public MainUser() {
wconstruct = new WindowConstruct("..:: User's Helpdesk Main Page ::..",
500, 500);
wconstruct.add(desktop);
wconstruct.btnNew.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == wconstruct.btnNew) {
InternalWindows.setSize(500, 300);
InternalWindows.setTitle("New task");
InternalWindows.setLayout(null);
InternalWindows.setClosable(true);
InternalWindows.setLocation(100, 50);
desktop.add(InternalWindows);
InternalWindows.setVisible(true);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainUser();
}
});
}
class WindowConstruct extends JFrame {
JButton btnNew = new JButton("Add New");
public WindowConstruct(String title, int width, int height) {
super(title);
setSize(width, height);
add(btnNew, BorderLayout.PAGE_END);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.