带有区域设置的JTable打印对话框 [英] JTable Printing dialog with Locale
问题描述
我尝试使用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 ..
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屋!