LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Java JTextPane (http://www.linuxquestions.org/questions/programming-9/java-jtextpane-787535/)

Martin_J 02-07-2010 03:35 AM

Java JTextPane
 
Hello, please can someone show me code to make my JTextArea scrollable ?
I used this code but it doesn't scroll just expand my JTextArea out of JFrame.
Part of code I used(one that doesn't work):
Quote:

public class GraphicsDemo {
public GraphicsDemo {
/*Previous code*/
JFrame frame = new JFrame("New Frame");
JPanel panel = new JPanel();

output = new JTextArea(5,30);
output.setEditable(false);
JScrollPane scrollPane = new JScrollPane(output);

panel.add(output);
panel.add(scrollPane);
frame.add(panel);
frame.setVisible(true);
frame.setSize(300,300);
}
}
Similar code is in in Java 6 Official Tutorial
http://java.sun.com/docs/books/tutor...crollpane.html
http://java.sun.com/docs/books/tutor...olBarDemo.java

aspire1 02-07-2010 04:18 AM

Code:

import javax.swing.*;
import java.awt.BorderLayout;

public class GraphicsDemo {
  public GraphicsDemo (){
    /*Previous code*/
    JFrame frame = new JFrame("New Frame");
 
    JTextArea jTextArea = new JTextArea( 30, 50 );
    JScrollPane jScrollPane = new JScrollPane( jTextArea );
   
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.setSize( 300, 300);
    frame.add( jScrollPane, BorderLayout.CENTER );
    frame.setVisible( true );
 
   
  }
 
  public static void main(String[] args){
      new GraphicsDemo();
  }
}


Martin_J 02-07-2010 06:05 AM

Ach, it's clear now, thanks.


All times are GMT -5. The time now is 01:04 PM.