2012-04-11 4 views
1

기본 UI가 클라이언트 영역과 도구라는 두 개의 JFrame으로 구성된 Java 응용 프로그램이 있습니다. 팔레트는 항상 클라이언트 영역 위에 표시되어야합니다. 이를 위해 도구 팔레트는 alwaysOnTop (true)로 설정됩니다.이 경우 모든 경우에 Windows 전용으로 저장됩니다. 모달 JDialog가 팝업되면 클라이언트 영역 및/또는 팔레트 (둘 다 차단됨) 팔레트가 클라이언트 영역 뒤쪽으로 떨어집니다. 모달 대화 상자가 닫히면 팔레트가 다시 나타나지만 "항상 맨 위"가 손실됩니다. 클라이언트 영역을 클릭하면 팔레트가 가려집니다. 여기 모달 대화 상자가 팝업되어 차단 된 JFrame이 클릭되면 JFrame이 z 순서의 맨 아래로 떨어집니다.

은 최소한의, 단일 소스 파일의 데모입니다 :

// FloatingPaletteExample.java 
// 4/11/2012 sorghumking 
// 
// Demo of a Windows-only issue that has me puzzled: When a modal dialog is 
// opened, and user clicks in blocked JFrames (sequence depends on ownership of 
// modal dialog: follow the instructions in modal dialog to see the problem 
// behavior), the floating tool palette loses its "always on top-ness". 

import javax.swing.*; 

import java.awt.BorderLayout; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.WindowAdapter; 
import java.awt.event.WindowEvent; 

public class FloatingPaletteExample { 
    public static void main(String [] args) { 
     final JFrame clientAreaJFrame = new JFrame("client JFrame"); 
     clientAreaJFrame.addWindowListener(new WindowAdapter() { 
      public void windowClosing(WindowEvent windowevent) { 
       clientAreaJFrame.dispose(); 
       System.exit(0); 
      } 
     }); 

     clientAreaJFrame.setSize(800, 600); 
     clientAreaJFrame.setVisible(true); 

     final JFrame floatingToolFrame = new JFrame("tool JFrame"); 
     final JCheckBox ownerCheckbox = new JCheckBox("Owned by tool frame (otherwise, null owner)"); 
     JButton popModalButton = new JButton("Open Modal Dialog"); 
     popModalButton.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
       JFrame owner = ownerCheckbox.isSelected() ? floatingToolFrame : null; 
       JDialog modalDialog = new JDialog(owner, "Modal Dialog", true); 
       final String labelText = ownerCheckbox.isSelected() ? "Click anywhere in the client JFrame." : 
                     "Click the tool JFrame, then anywhere in the client JFrame"; 
       modalDialog.add(new JLabel(labelText)); 
       modalDialog.pack(); 
       modalDialog.setLocation(100, 100); 
       modalDialog.setVisible(true); 
      } 
     }); 
     floatingToolFrame.add(popModalButton, BorderLayout.NORTH); 
     floatingToolFrame.add(ownerCheckbox, BorderLayout.SOUTH); 

     floatingToolFrame.pack(); 
     floatingToolFrame.setLocationRelativeTo(clientAreaJFrame); 
     floatingToolFrame.setAlwaysOnTop(true); 
     floatingToolFrame.setVisible(true); 
    } 
} 
내가 the doc에 따라 "응용 프로그램이 AWT에있는 것입니다 창을 식별하기위한 표준 메커니즘 (false)를 floatingToolFrame.setFocusableWindowState을 시도

부동 팔레트 또는 도구 모음 "으로 사용되지만 동작은 동일하게 유지됩니다.

해결 방법을 찾았습니다. 모달 대화 상자를 표시하기 전에 floatingToolFrame.setAlwaysOnTop (false)를 호출하고 닫은 후에 floatingToolFrame.setAlwaysOnTop (true)를 호출합니다. 그러나 모달 대화 상자가 열릴 때마다이 배치를 요구하는 것은 터무니없는 것처럼 보입니다. 네, JDialog를 서브 클래스화할 수 있고, 서브 클래스에서 모든 대화 상자를 파생시킬 수 있습니다. 그렇지만 다시 필요한 이유는 무엇입니까?

해결 방법없이 문제를 해결하는 방법에 대한 아이디어가 있으십니까? Always-on-top 팔레트를 완전히 잘못 작성하는 것에 대한 나의 접근 방식은 무엇입니까? (한 가지 더 메모 : 여기에 설명 된 문제와 반대되는 것으로 나타납니다 : Java 6, JFrame stuck alwaysontop).

의견을 보내 주시면 감사하겠습니다.

답변

0

내게 큰 호응을 얻으려면이 문제는 Java 7 SE! 위의 예는 7u4 Build b20에 대해 올바르게 작동합니다.

관련 문제