JTable Printing dialog with Locale

我的未来我决定 提交于 2019-12-12 05:16:59

问题


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!


回答1:


@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.



来源:https://stackoverflow.com/questions/17840588/jtable-printing-dialog-with-locale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!