2011-11-18 14 views

risposta

17

Per inserire una barra di scorrimento sul nuovo JTextPane, basta usare 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

Se si dispone di alcuni problemi , dai un'occhiata a questa domanda SO: Java JTextPane JScrollPane Display Issue

Oppure dare un'occhiata a: http://www.daniweb.com/software-development/java/threads/30283

2

Basta inserire JTextPane in 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

Prima di questo è sufficiente aggiungere uno ScrollPane a ContentPane in Design e aggiungere EditopPane a ScrollPane come figlio

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

Ecco il codice per aggiungere una barra di scorrimento per il controllo TextBox

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); 

aggiungere il componente "spEditor" al JPanel

Problemi correlati