如何从JasperViewer中删除保存按钮?我发现了一种方法,但它来自JRViewer组件,我根本不相信。
答案 0 :(得分:1)
我知道这已经过时了,但是在我开始工作之前我偶然发现了这一点,所以为了未来的研究人员,我将在这里展示对我有用的东西。
import javax.swing.JPanel;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
public class MyJasperViewer extends JasperViewer {
public MyJasperViewer(JasperPrint jasperPrint, boolean isExitOnClose) {
super(jasperPrint, isExitOnClose);
try {
((JPanel) this.viewer.getComponent(0)).remove(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
现在就像这样使用它
JasperPrint jp = JasperFillManager.fillReport(url.openStream(), map, conn);
MyJasperViewer jv = new MyJasperViewer(jp, false);
jv.setVisible(true);
答案 1 :(得分:1)
private void adjustViewerLayoutAndLookAndShow(JasperViewer viewer) {
Container contentPane = viewer.getContentPane();
JRViewerToolbar toolbar = (JRViewerToolbar) ((JRViewer)((JPanel)contentPane.getComponents()[0]).getComponent(0)).getComponent(0);
JButton btnSave = (JButton) toolbar.getComponent(0);
btnSave.setEnabled(false);
JButton btnPrint = (JButton) toolbar.getComponent(1);
btnSave.setEnabled(false);
viewer.setTitle(extraInfo);
viewer.setVisible(true);
}