2014-03-25 3 views
0

MDI 프로젝트가 있습니다. JInternalFrame에 고객 JPanel을 추가합니다. 내 고객 JPanel에는 일부 구성 요소 배경색을 변경하는 public 메서드가 있습니다. JFrame의 버튼을 클릭하면 모든 InternalFrame에 대해 고객 JPanel의 레이블이나 텍스트를 변경해야합니다. 방법을 어떻게 호출 할 수 있습니까? 미리 감사는JFrame의 모든 JInternalFrame에 대한 라벨을 변경하려면 고객 JPanel의 메소드를 호출하십시오.

다음 코드는

private void AddNote(File file){   
     JInternalFrame internalFrame = new  JInternalFrame("PDFAnnotation" 
       + file.getName(), true, true, true, true);  
     internalFrame.setBounds(0, 0, 600, 100); 
     desktop.add(internalFrame);  


     PDFJPanel p=new PDFJPanel(file);  
     internalFrame.add(p, BorderLayout.CENTER); 
     internalFrame.setVisible(true); 
try { 
      internalFrame.setSelected(true); 
     } 
     catch (java.beans.PropertyVetoException e) {} 
     this.add(desktop, BorderLayout.CENTER); 

     //resize the internal frame as full screen 
     Dimension size = desktop.getSize(); 
     int w = size.width ; 
     int h = size.height ; 
     int x=0; 
     int y=0; 
     desktop.getDesktopManager().resizeFrame(internalFrame, x, y, w, h); 
    } 

내 고객의 방법이 다음 코드는 바탕 화면에 내부 프레임을 추가입니다 JFrame의

private void categoryAction(ActionEvent e){ 
    try{ 
     JButton b=(JButton)e.getSource(); 
     Color c=b.getBackground(); 
     JInternalFrame[] allframes = desktop.getAllFrames(); 
     int count = allframes.length; 
     for (int i=0; i<allframes.length-1; i++){ 
      //call the method on the PDFJPanel 
     } 

    } 
    catch(Exception err){ 
     Utility.DisplayErrorMsg(err.toString()); 

    } 

에있는 버튼에 대한 조치입니다 JPanel

Public void setDefaultColor(Color c){ 
     //change the label and textbox color 
} 

답변

2

커서를 반환하는 JDesktopPane.getSelectedFrame을 사용할 수 있습니다. ently 활성 프레임. 레이아웃 관리자에서 PDFJPanel을 검색 할 수 있습니다 (예 : BorderLayout.getLayoutComponent()). 또는 쉽고 청소기, 당신은 즉, JInternalFrame 확장 할 수

다음
class PDFFrame extends JInternalFrame { 
    private PDFJPanel panel; 

    public PDFFrame(File file) { 
     panel = new PDFJPanel(file); 
     add(panel, BorderLayout.CENTER); 
    } 

    public void setDefaultColor(Color c){ 
     panel.setDefaultColor(); 
    } 
} 

, 액세스합니다 :

JDesktopPane desktop = ...; 

PDFFrame frame = (PDFFrame) desktop.getSelectedFrame(); 
frame.setDefaultColor(Color.BLUE); 
+0

나는 모든 프레임을 변경해야 할뿐만 아니라, 현재 활성화 된 프레임. – user819774

+0

@ user819774 [JDesktopPane.getAllFrames()] 참조 (http://docs.oracle.com/javase/7/docs/api/javax/swing/JDesktopPane.html#getAllFrames%28%29) – tenorsax

+0

getAllFrames () 내 코드에서 모든 프레임을 얻을 수 있지만 모든 내부 프레임에 대한 PDFJPanel 가져 오는 방법을 모르겠습니다. 보여 주시겠습니까? 감사. – user819774