带有区域设置的JTable打印对话框 [英] JTable Printing dialog with Locale

查看:247
本文介绍了带有区域设置的JTable打印对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java Swing。
我尝试使用Jtable的print方法...

  public void actionPerformed(java.awt.event.ActionEvent ignore ){
MessageFormat header = new MessageFormat(Page {0,number,integer});
try {
table.print(JTable.PrintMode.FIT_WIDTH,header,null);
} catch(java.awt.print.PrinterException e){
System.err.format(Can not print%s%n,e.getMessage());
}
}

显示打印对话框。它的工作很好..



打印对话框



但是,我想使用Locale类将文本对话框语言更改为西班牙语,我该怎么办?



谢谢!

解决方案

@Diego



我在这里复制了你的解决方案,这样可以更容易地阅读。



这是激进的旧论坛条目: https://forums.oracle.com/thread/1287832



--- - 开始----



在Jtable.print()方法之前添加反射来更改ResourceBlunde ...

  try {
Class cl = Class.forName(sun.print.ServiceDialog);
if(cl!= null){
Field fld = cl.getDeclaredField(messageRB);
if(fld!= null){
fld.setAccessible(true);
fld.set(cl,ResourceBundle.getBundle(sun.print.resources.serviceui_es));
}
}
} catch(Exception ex11){
ex11.printStackTrace();
}

----结束----



我可能想在某天搜索并找到它。


im working with Java Swing. Im trying with print method of Jtable...

public void actionPerformed(java.awt.event.ActionEvent ignore) {
    MessageFormat header = new MessageFormat("Page {0,number,integer}");
    try {
        table.print(JTable.PrintMode.FIT_WIDTH, header, null);
    } catch (java.awt.print.PrinterException e) {
        System.err.format("Cannot print %s%n", e.getMessage());
    }
}

To show a printing dialog . Its work fine ..

The printing dialog

But i want to change the text dialog language to Spanish with a Locale class , how can i do it ???

Thanks!

解决方案

@Diego

I copied your solution here so it can be more easily read.

It was inspire by the old forum entry here: https://forums.oracle.com/thread/1287832

---- Begin ----

Just adding reflection to change the ResourceBlunde before Jtable.print() method...

try { 
    Class cl = Class.forName("sun.print.ServiceDialog"); 
    if (cl != null) { 
        Field fld = cl.getDeclaredField("messageRB"); 
        if (fld != null) { 
            fld.setAccessible(true); 
            fld.set(cl, ResourceBundle.getBundle("sun.print.resources.serviceui_es")); 
        } 
    } 
} catch (Exception ex11) { 
    ex11.printStackTrace(); 
}

---- End ----

I may want to search and find it someday.

这篇关于带有区域设置的JTable打印对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆