java 自定义报表_图解自定义java报表菜单实现五大步

本文介绍了如何在Java中自定义报表菜单,包括创建SaveReportAction类,设置相关方法和事件处理,以及在设计器中配置菜单文件,最终实现在设计器中看到自定义的"保存"按钮。
摘要由CSDN通过智能技术生成

1.写一个Java文件如SaveReportAction所示,其包名为com.demo,编译这个Java文件为类文件,保存到设计器的classpath下面。代码如下:

package com.demo;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

import com.fr.base.BaseUtils;

import com.fr.base.Inter;

import com.fr.cell.JWorkBook;

import com.fr.cell.ReportPane;

import com.fr.design.actions.UpdateAction;

import com.fr.design.gui.core.DesignUtils;

import com.fr.design.mainframe.DesignerContext;

import com.fr.design.mainframe.JReportInternalFrame;

import com.fr.report.Report;

public class SaveReportAction extends UpdateAction {

public SaveReportAction() {

this.setName(Inter.getLocText("M-Save"));

this.setMnemonic('S');

this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/save.png"));

this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));

}

public void actionPerformed(ActionEvent arg0) {

JReportInternalFrame reportFrame = DesignUtils.getReportFrame(DesignerContext.getDesignerFrame());

if(reportFrame == null) {

return;

}

ReportPane reportPane = reportFrame.getReportPane();

Report report;

if(reportPane instanceof JWorkBook) {

report = ((JWorkBook)reportPane).getWorkBook();

} else {

report = reportPane.getReport();

}

// 可以通过TemplateExporter导出该Report

System.out.println("Report.getRowCount is " + report.getRowCount());

}

}

2.打开设计器,主菜单 | 窗口 | 选项,打开对话框导出菜单配置文件

94.png%20

3.修改menu.xml

95.png%20

4.再次打开设计器,主菜单 | 窗口 | 选项,打开对话框,指定菜单配置文件的目录为D:"menu.xml

96.png%20

5.重启设计器,可以看到File菜单下多了一个”保存”按钮

97.png%20

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值