【问题标题】:java webstart System.getProperties() or Syste.setProperties() is ignoredjava webstart System.getProperties() 或 Syste.setProperties() 被忽略
【发布时间】:2018-02-14 15:37:37
【问题描述】:

我有一个使用 JXLayer 和 pbjar-Framework 的带有可缩放 UI 的 java swing 项目。 JTextComponents 存在一个问题,该问题已通过 TransformUI.java 中的以下方法修复:

/**
 * {@link JTextComponent} and its descendants have some caret position
 * problems when used inside a transformed {@link JXLayer}. When you plan to
 * use {@link JTextComponent}(s) inside the hierarchy of a transformed
 * {@link JXLayer}, call this method in an early stage, before instantiating
 * any {@link JTextComponent} .
 * <p>
 * It executes the following method:
 * 
 * <pre>
 * System.setProperty(&quot;i18n&quot;, Boolean.TRUE.toString());
 * </pre>
 * 
 * As a result, a {@link GlyphPainter} will be selected that uses floating
 * point instead of fixed point calculations.
 * </p>
 */
public static void prepareForJTextComponent() {
  System.setProperty("i18n", Boolean.TRUE.toString());
}

所有 JAR 都使用有效证书签名,jnlp 看起来像

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="7.0+" codebase="https://__HOST_IP____HOST_HTTPS_PORT__/test"
  href="client/1024.jnlp">
  <information>
    <offline-allowed />
  </information>
  <security>
    <all-permissions />
  </security>
  <resources>
    <j2se version="1.8+" java-vm-args="-Xmx512M" />
    <jar href="client.jar" />
    ... more JARs
  </resources>
  <application-desc main-class="de.test.Frame">
    <argument>__HOST_IP__</argument>
  </application-desc>
</jnlp>

client.jar MANIFEST.MF 包含以下内容

...
Permissions: all-permissions
Codebase: *
Trusted-Only: false
Trusted-Library: false
...

因为 javaws 只接受我在主类中调用的安全属性

static
{
  TransformUI.prepareForJTextComponent();
}

问题是,如果我在每个浏览器中使用 Java webstart,则 JTextComponent 的修复不起作用。

对于java webstart我测试了4个案例:

  1. java
  2. javaws [网址]
  3. javaws [本地文件]
  4. 浏览器

使用 oracle java 8u141、32 或 64 位、Windows 7 64 位、linux debian 7 64 位、firefox 进行测试 java

如果我将客户端称为 java 应用程序,则修复工作正常

javaws [url]

此调用在 linux 和 windows 中运行良好。 但是在旧版本的 jnlp 文件中,我们使用扩展来包含 3rd-party JAR,在 Windows 中,这个调用会工作一次,直到我删除缓存的文件

javaws [本地文件]

没用

浏览器

没用

有什么建议为什么系统属性不起作用?

【问题讨论】:

    标签: java swing java-web-start java-security


    【解决方案1】:

    在 javax.swing.text.AbstractDocument.AbstractDocument(Content, AttributeContext) 中读取 SystemProperty "i18n":

    ...
    if (defaultI18NProperty == null) {
      // determine default setting for i18n support
      String o = java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction<String>() {
          public String run() {
            return System.getProperty(I18NProperty);
          }
        }
      );
      if (o != null) {
        defaultI18NProperty = Boolean.valueOf(o);
      } else {
        defaultI18NProperty = Boolean.FALSE;
      }
    }
    putProperty( I18NProperty, defaultI18NProperty);
    ....
    

    在我的情况下,该属性应始终设置为“true”,因此我使用自己的 JTextField 类:

    class MyTextField extends JTextField {
      MyTextField() {
        super();
        Document doc = new PlainDocument();
        doc.putProperty("i18n", Boolean.TRUE);
        this.setDocument(doc);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多