使用RTextArea 遇到的问题
- heightTextField = new RTextArea("abc");
运行时报错:
- java.lang.NullPointerException
- at javax.swing.text.JTextComponent.setCaretPosition(JTextComponent.java:1680)
- at javax.swing.text.JTextComponent.select(JTextComponent.java:1922)
- at javax.swing.JTextArea.<init>(JTextArea.java:213)
- at javax.swing.JTextArea.<init>(JTextArea.java:150)
- at org.fife.ui.rtextarea.RTextAreaBase.<init>(RTextAreaBase.java:114)
- at org.fife.ui.rtextarea.RTextArea.<init>(RTextArea.java:205)
- at com.swing.dialog.SpecifyWidthAndHeightDialog.<init>(SpecifyWidthAndHeightDialog.java:76)
- at com.swing.dialog.SpecifyWidthAndHeightDialog$1.run(SpecifyWidthAndHeightDialog.java:40)
- at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
- at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
- at java.awt.EventQueue.access$200(EventQueue.java:103)
- at java.awt.EventQueue$3.run(EventQueue.java:694)
- at java.awt.EventQueue$3.run(EventQueue.java:692)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
- at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
- at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
- at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
- at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
- at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
- at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
- at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
但是下面的程序是没有问题的:
- package com.swing.test;
- import com.swing.dialog.GenericFrame;
- import org.fife.ui.rtextarea.RTextArea;
- import java.awt.*;
- /**
- * Created by huangweii on 2016/1/10.
- */
- public class TestFrame extends GenericFrame {
- @Override
- public void layout3(Container contentPane) {
- super.layout3(contentPane);
- setLoc(200,200);
- RTextArea rTextArea=new RTextArea();
- rTextArea.setText("文本内容");
- contentPane.add(rTextArea);
- }
- public static void main(String[]args){
- new TestFrame().launchFrame();
- }
- }
pom.xml:
- <dependency>
- <groupId>com.fifesoft</groupId>
- <artifactId>rsyntaxtextarea</artifactId>
- <version>r239</version>
- </dependency>