Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JTextPane未包装文本_Java_Swing_Jtextpane - Fatal编程技术网

Java JTextPane未包装文本

Java JTextPane未包装文本,java,swing,jtextpane,Java,Swing,Jtextpane,我遇到了一个奇怪的问题。我在JscrollPane中有一个JtextPane,它在通讯组列表中显示了一个大字符串,当我使用eclipse运行程序时,它正确地包装了代码,但当我使用java webstart运行同一程序时,它停止了包装文本 这是我的密码: private JScrollPane displayResults(String distributionList) { // TODO Auto-generated method stub JTextPane textArea =

我遇到了一个奇怪的问题。我在
JscrollPane
中有一个
JtextPane
,它在通讯组列表中显示了一个大字符串,当我使用eclipse运行程序时,它正确地包装了代码,但当我使用java webstart运行同一程序时,它停止了包装文本

这是我的密码:

   private JScrollPane displayResults(String distributionList) {
// TODO Auto-generated method stub
  JTextPane textArea = new JTextPane();
  textArea.setText(distributionList);
  textArea.setEditable(false);
  JScrollPane scrollPane = new JScrollPane(textArea);  
  scrollPane.setPreferredSize( new Dimension( 500, 500 ) );
  return scrollPane;
}

原因可能是java版本

看看在哪里讨论了它,并提供了一个变通方法。这项工作对我来说很好

      textArea.setEditorKit(new HTMLEditorKit(){ 
     @Override 
     public ViewFactory getViewFactory(){ 

         return new HTMLFactory(){ 
             public View create(Element e){ 
                View v = super.create(e); 
                if(v instanceof InlineView){ 
                    return new InlineView(e){ 
                        public int getBreakWeight(int axis, float pos, float len) { 
                            return GoodBreakWeight; 
                        } 
                        public View breakView(int axis, int p0, float pos, float len) { 
                            if(axis == View.X_AXIS) { 
                                checkPainter(); 
                                int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len); 
                                if(p0 == getStartOffset() && p1 == getEndOffset()) { 
                                    return this; 
                                } 
                                return createFragment(p0, p1); 
                            } 
                            return this; 
                          } 
                      }; 
                } 
                else if (v instanceof ParagraphView) { 
                    return new ParagraphView(e) { 
                        protected javax.swing.SizeRequirements calculateMinorAxisRequirements(int axis, javax.swing.SizeRequirements r) { 
                            if (r == null) { 
                                  r = new javax.swing.SizeRequirements(); 
                            } 
                            float pref = layoutPool.getPreferredSpan(axis); 
                            float min = layoutPool.getMinimumSpan(axis); 
                            // Don't include insets, Box.getXXXSpan will include them. 
                              r.minimum = (int)min; 
                              r.preferred = Math.max(r.minimum, (int) pref); 
                              r.maximum = Integer.MAX_VALUE; 
                              r.alignment = 0.5f; 
                            return r; 
                          } 

                      }; 
                  } 
                return v; 
              } 
          }; 
      } 
  }); 

好的,我尝试了上面提到的解决方案,但遇到了一个异常。线程“thread-40”java.lang.ClassCastException中的异常:javax.swing.text.DefaultStyledDocument与javax.swing.text.html.htmlDocument不兼容这不是/不可能对所有Java7版本都有效,@StanislavL,请使用您的代码workaround@mKorbel我会尽力调查,但不确定什么时候我会有足够的钱time@StanislavL糟糕的是,我错过了阅读JTextPane而不是JTextArea的机会