Java - Leer texto de archivo rtf que esta en un JtextPane

 
Vista:
Imágen de perfil de Brian

Leer texto de archivo rtf que esta en un JtextPane

Publicado por Brian (8 intervenciones) el 10/06/2015 03:14:35
Hola,no encuentro la manera de obtener el texto de un JtextPane ,intente con getText pero me devuelve null ,en mi textpane abro un archivo rtf me muestra en archivo pero cuando quiero obtener el texto no encuentro la manera d ehacerlo.Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Leer texto de archivo rtf que esta en un JtextPane

Publicado por Mauricio (1 intervención) el 10/06/2015 17:49:28
JEditorPane:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class CodeTabs extends JTabbedPane {
  private JTextPane codearea;
  private JScrollPane scroll;
 
  public CodeTabs() {
    setTabPlacement(JTabbedPane.BOTTOM);
 
    codearea = new JTextPane();
 
    scroll = new JScrollPane(codearea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setPreferredSize(new Dimension(  300,300 ));
 
    JPanel panel = new JPanel( new BorderLayout() );
    panel.add( scroll, BorderLayout.CENTER );
    JButton comp = new JButton( "Print text" );
    comp.addActionListener( new ActionListener() {
      @Override
      public void actionPerformed( ActionEvent e ) {
        getCode();
      }
    } );
    panel.add( comp, BorderLayout.SOUTH );
 
    addTab( "Code", panel );
  }
 
  public String getCode() {
  //  String s = codearea.getText();
String s = codearea.getDocument().getText(0, codearea.getDocument().getLength());
    System.out.println(s);
 
    return s;
  }
 
  public static void main( String[] args ) {
    EventQueue.invokeLater( new Runnable() {
      @Override
      public void run() {
        JFrame frame = new JFrame( "TestFrame" );
        frame.getContentPane().add( new CodeTabs() );
        frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible( true );
      }
    } );
  }

Bye!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar