LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2010, 03:35 AM   #1
Martin_J
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Rep: Reputation: 0
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
 
Old 02-07-2010, 04:18 AM   #2
aspire1
Member
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 62

Rep: Reputation: 23
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(); 
  }
}
 
1 members found this post helpful.
Old 02-07-2010, 06:05 AM   #3
Martin_J
LQ Newbie
 
Registered: Feb 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Ach, it's clear now, thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu 7.10 64bit - how to set java path to/redirect java to libjvm.so ? Thane Ubuntu 1 03-25-2008 05:52 PM
LXer: Java news met with cautious optimism in free Java community LXer Syndicated Linux News 0 11-14-2006 10:21 PM
Firefox refuses to load Java jnlp files - plugin and java ok Melsync Linux - Software 1 06-25-2006 04:09 PM
JTextPane Won't Resize ElementNine Programming 5 02-28-2004 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration