0
我有MDI项目。我在JInternalFrame中添加了客户JPanel。我的客户JPanel有一个公开的方法来改变一些组件背景颜色。当单击JFrame上的按钮时,我希望它更改我的客户JPanel上所有InternalFrame的标签或文本。我怎样才能调用这个方法?在此先感谢调用我的客户JPanel上的方法来更改JFrame中所有JInternalFrame的标签
下面的代码是在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());
}
按钮的动作下面的代码添加内部框架到桌面
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);
}
有我的客户的方法JPanel
Public void setDefaultColor(Color c){
//change the label and textbox color
}
我需要改变所有的框架,不仅当前有效的框架。 – user819774
@ user819774请参阅[JDesktopPane.getAllFrames()](http://docs.oracle.com/javase/7/docs/api/javax/swing/JDesktopPane.html#getAllFrames%28%29) – tenorsax
我使用了getAllFrames( )在我的代码来获取所有帧,但我不知道如何获得所有内部框架的PDFJPanel。你会告诉我吗?谢谢。 – user819774