[英]Call the method on my customer JPanel for changing label for all JInternalFrames in JFrame
I have MDI project. 我有MDI项目。 I add the customer JPanel in the JInternalFrame.
我在JInternalFrame中添加了客户JPanel。 My customer JPanel has a public method to change some component background color.
我的客户JPanel有一个公共方法来更改某些组件背景颜色。 When the button on the JFrame is clicked, I want it to change the label or text on my customer JPanel for all InternalFrame.
单击JFrame上的按钮时,我希望它更改客户JPanel上所有InternalFrame的标签或文本。 How can I call the method?
我怎么称呼这个方法? Thanks in advance
提前致谢
The following code is the action for the button on JFrame 以下代码是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());
}
The following code is add the internal frame into the desktop 以下代码将内部框架添加到桌面
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);
}
There is the method on my customer JPanel 我的客户JPanel上有方法
Public void setDefaultColor(Color c){
//change the label and textbox color
}
You can utilize JDesktopPane.getSelectedFrame that returns currently active frame. 您可以使用返回当前活动帧的JDesktopPane.getSelectedFrame 。 You can retrieve
PDFJPanel
from the layout manager, ie using BorderLayout.getLayoutComponent()
. 您可以从布局管理器中检索
PDFJPanel
,即使用BorderLayout.getLayoutComponent()
。 Or easier and cleaner, you can extend JInternalFrame
, ie: 或者更简单,更清洁,您可以扩展
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();
}
}
Then, access it: 然后,访问它:
JDesktopPane desktop = ...;
PDFFrame frame = (PDFFrame) desktop.getSelectedFrame();
frame.setDefaultColor(Color.BLUE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.