2011-11-18 18 views

Respuesta

17

Para insertar una barra de desplazamiento en su nueva JTextPane, sólo tiene que utilizar un JScrollPane:

JTextPane txt = new JTextPane(); 

JScrollPane jsp = new JScrollPane(txt); 

JTextPane API: http://download.oracle.com/javase/6/docs/api/javax/swing/JTextPane.html

JScrollPane API: http://download.oracle.com/javase/6/docs/api/javax/swing/JScrollPane.html

Si usted tiene algunos problemas , eche un vistazo a esta pregunta ASÍ: Java JTextPane JScrollPane Display Issue

O echar un vistazo a: http://www.daniweb.com/software-development/java/threads/30283

2

Simplemente ponga el JTextPane en un JScrollPane.

public class SomeFrame 
{ 
    public static void main(String[] args) 
    { 
    JFrame frame = new JFrame(); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    JTextPane tp = new JTextPane(); 
    JScrollPane sp = new JScrollPane(tp); 
    frame.getContentPane().add(sp); 

    frame.pack(); 
    frame.setVisible(true); 
    } 
} 
0

Antes de esto sólo tiene que añadir un ScrollPane a ContentPane en Diseño y añadir EditopPane a ScrollPane como niño

JScrollPane sp = (JScrollPane)contentPane.getComponent(23);//this is in my hierarchy 23 
JViewport vp = sp.getViewport(); 
JEditorPane ep = (JEditorPane)vp.getView(); 
0

Este es el código para agregar una barra de desplazamiento para el cuadro de texto

JEditorPane edtDTWinfo = new JEditorPane(); 
    edtDTWinfo.setEditable(false); 
    edtDTWinfo.setBorder(new LineBorder(Color.ORANGE, 2)); 
    edtDTWinfo.setForeground(Color.BLUE); 
    JScrollPane spEditor = new JScrollPane(edtDTWinfo, 
      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 
    spEditor.setBounds(0, 0, 200, 300); 

Agregar componente "spEditor" al JPanel

Cuestiones relacionadas