5 Replies Latest reply: Jan 18, 2005 4:50 PM by 843810 RSS

    PrinterJob.printDialog localization problem

    843810
      Hi!
      Can you help me please to solve my problem?
      I would like to print from applet by using native Java print dialog:
      java.awt.print.PrinterJob.printDialog(attr)
      where attr is
      javax.print.attribute.HashPrintRequestAttributeSet()
      Current locale is Russian but print dialog started in default (en,US) language.
      Resourse bundle for print dialog there are in rt.jar: sun.print.resources.serviceui*.properties But no serviceui_ru_RU.properties there. I can create sun.print.resources.serviceui_ru_RU.properties with russian string resources.
      How i must use it with my applet so that applet page visitor can see print dialog in russian (in case of russian locale as default at his system of course)?
        • 1. Re: PrinterJob.printDialog localization problem
          843810
          Please

          I have same problem (but with Portuguese). Did you resolve this question?

          Thank's
          • 2. Re: PrinterJob.printDialog localization problem
            843810
            Using reflection, you can manipulate that "private static" ResourceBundle in class
            sun.print.ServiceDialog.
            Of cource, the code must have access rights to do that, so it usually has to run as application, not as a restricted applet.
            If requested, I will post that few lines of code here.
            What I ask for, is the file 'sun.print.resources.serviceui_ru.properties', because I can not make that translation myself.
            Thanks.
            Heinz-Peter
            • 3. Re: PrinterJob.printDialog localization problem
              843810
              Sure, please do. I'm, too, curious at how to localize Java Print and Page Setup dialogs. Thanks.
              • 4. Re: PrinterJob.printDialog localization problem
                843810
                        Locale.setDefault(...);
                
                        // reload ResourceBundle according to locale set above
                        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"));
                                }
                            }
                        }
                        catch (Exception ex11)
                        {
                            ex11.printStackTrace();
                        }
                Good luck!
                Heinz-Peter
                • 5. Re: PrinterJob.printDialog localization problem
                  843810
                  There may be other files that need be localized also, I think:

                  sun.awt.print.resources.pdialog.properties
                  sun.awt.print.resources.printcontrol.properties