Results 1 to 8 of 8
- 05-11-2012, 07:00 AM #1
Member
- Join Date
- May 2012
- Location
- Yamuna Nagar,Haryana,India
- Posts
- 28
- Rep Power
- 0
- 05-11-2012, 07:39 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: poblem in making textarea scrollable over JPanel
You need to wrap your textarea in a JScrollPane component. This will add scrolling capability to the textarea.
Website: Learn Java by Examples
- 05-11-2012, 08:02 AM #3
Member
- Join Date
- May 2012
- Location
- Yamuna Nagar,Haryana,India
- Posts
- 28
- Rep Power
- 0
Re: poblem in making textarea scrollable over JPanel
i already wrap the textarea in JScrollPane component...but still its not working
- 05-11-2012, 08:48 AM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: poblem in making textarea scrollable over JPanel
Can you post the section of your program that related how you create a text area and place it inside a scroll pane?
Website: Learn Java by Examples
- 05-11-2012, 08:51 AM #5
Member
- Join Date
- May 2012
- Location
- Yamuna Nagar,Haryana,India
- Posts
- 28
- Rep Power
- 0
Re: poblem in making textarea scrollable over JPanel
this is the code......i uses a different class for making textarea scrollable
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class text extends JFrame implements KeyListener
{
JPanel jp;
boolean txtChanged = false;
JTextArea t;
File file;
String fname = "";
String buf="";
Container c;
text()
{
setUndecorated(true);
setVisible(true);
setResizable(true);
setLocation(550,100);
setSize(600,650);
setDefaultCloseOperation(EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("icon.png");
setIconImage(img.getImage());
jp=new JPanel();
jp.setLayout(null);
t=new JTextArea();
JScrollPane scroll= new JScrollPane(t);
t.setBorder(BorderFactory.createLineBorder(Color.b lack));
t.setFocusable(true);
//t.setEditable(false);
scroll.setVisible(true);
c = getContentPane();
c.setLayout(new BorderLayout());
//add(jp);
c.add(scroll, BorderLayout.CENTER);
t.addKeyListener(this);
try
{
FileReader fr=new FileReader("intro.txt");
BufferedReader br=new BufferedReader(fr);
while ((buf=br.readLine()) != null)
{
t.append(buf);
t.append("\n");
}
br.close();
fr.close();
}
catch (IOException evt)
{
System.out.println("Exception: " + evt);
}
}
public void keyPressed(KeyEvent e)
{
//System.out.println("KP");
}
public void keyReleased(KeyEvent e)
{
//System.out.println("KR");
}
public void keyTyped(KeyEvent ke)
{
txtChanged = true;
}
}
public class array extends JFrame implements ActionListener
{
JPanel jp;
static JButton basic,operation,user_practice,menu;
JLabel bg,logo;
array()
{
super("Array-Data Structure Tutorial");
setVisible(true);
setResizable(true);
setLocation(0,0);
setSize(1200,780);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
ImageIcon img = new ImageIcon("icon.png");
setIconImage(img.getImage());
jp=new JPanel();
jp.setBounds(0,0,500,800);
jp.setLayout(null);
basic=new JButton("Basic Terminology",new ImageIcon("basic.jpg"));
operation=new JButton("Operations",new ImageIcon("operation.jpg"));
menu=new JButton("",new ImageIcon("home.png"));
user_practice=new JButton("User Practice",new ImageIcon("user.jpg"));
bg=new JLabel(new ImageIcon("bg1.jpg"));
logo=new JLabel(new ImageIcon("logo.png"));
Font f2=new Font("calibri",Font.PLAIN,20);
Font f3=new Font("Times New Roman",Font.BOLD,15);
basic.setFont(f2);
operation.setFont(f2);
user_practice.setFont(f2);
menu.setFont(f2);
add(jp);
jp.add(basic);
jp.add(operation);
jp.add(user_practice);
jp.add(menu);
jp.add(bg);
bg.add(logo);
basic.addActionListener(this);
operation.addActionListener(this);
user_practice.addActionListener(this);
menu.addActionListener(this);
basic.setBounds(100,160,250,60);
operation.setBounds(100,260,250,60);
user_practice.setBounds(100,560,250,60);
menu.setBounds(55,30,50,50);
bg.setBounds(0,0,1300,800);
logo.setBounds(700,1,850,80);
text t=new text();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==menu)
{
main m1=new main();
this.setVisible(false);
}
else if(e.getSource()==basic)
{
basicarray m1=new basicarray();
this.setVisible(false);
}
else if(e.getSource()==operation)
{
operations m2=new operations();
this.setVisible(false);
}
else if(e.getSource()==user_practice)
{
practicearray m4=new practicearray();
this.setVisible(false);
}
}
}
- 05-11-2012, 09:16 AM #6
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: poblem in making textarea scrollable over JPanel
Please format your code to make it easier to read, use the [code] tag for this.
By default when the text area have no data or if the data is visible without scrolling the scroll bar will not be displayed. If you want to change this default you can use the other JScrollPane constructor that accept the vertical and horizontal scrollbar policy.Website: Learn Java by Examples
- 05-15-2012, 09:42 AM #7
Member
- Join Date
- May 2012
- Location
- Yamuna Nagar,Haryana,India
- Posts
- 28
- Rep Power
- 0
Re: poblem in making textarea scrollable over JPanel
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; class text extends JFrame implements KeyListener { JPanel jp; boolean txtChanged = false; JTextArea t; File file; String fname = ""; String buf=""; Container c; text() { setUndecorated(true); setVisible(true); setResizable(true); setLocation(550,100); setSize(600,650); setDefaultCloseOperation(EXIT_ON_CLOSE); ImageIcon img = new ImageIcon("icon.png"); setIconImage(img.getImage()); jp=new JPanel(); jp.setLayout(null); t=new JTextArea(); JScrollPane scroll= new JScrollPane(t); t.setBorder(BorderFactory.createLineBorder(Color.b lack)); t.setFocusable(true); //t.setEditable(false); scroll.setVisible(true); c = getContentPane(); c.setLayout(new BorderLayout()); //add(jp); c.add(scroll, BorderLayout.CENTER); t.addKeyListener(this); try { FileReader fr=new FileReader("intro.txt"); BufferedReader br=new BufferedReader(fr); while ((buf=br.readLine()) != null) { t.append(buf); t.append("\n"); } br.close(); fr.close(); } catch (IOException evt) { System.out.println("Exception: " + evt); } } public void keyPressed(KeyEvent e) { //System.out.println("KP"); } public void keyReleased(KeyEvent e) { //System.out.println("KR"); } public void keyTyped(KeyEvent ke) { txtChanged = true; } } public class array extends JFrame implements ActionListener { JPanel jp; static JButton basic,operation,user_practice,menu; JLabel bg,logo; array() { super("Array-Data Structure Tutorial"); setVisible(true); setResizable(true); setLocation(0,0); setSize(1200,780); setDefaultCloseOperation(EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); ImageIcon img = new ImageIcon("icon.png"); setIconImage(img.getImage()); jp=new JPanel(); jp.setBounds(0,0,500,800); jp.setLayout(null); basic=new JButton("Basic Terminology",new ImageIcon("basic.jpg")); operation=new JButton("Operations",new ImageIcon("operation.jpg")); menu=new JButton("",new ImageIcon("home.png")); user_practice=new JButton("User Practice",new ImageIcon("user.jpg")); bg=new JLabel(new ImageIcon("bg1.jpg")); logo=new JLabel(new ImageIcon("logo.png")); Font f2=new Font("calibri",Font.PLAIN,20); Font f3=new Font("Times New Roman",Font.BOLD,15); basic.setFont(f2); operation.setFont(f2); user_practice.setFont(f2); menu.setFont(f2); add(jp); jp.add(basic); jp.add(operation); jp.add(user_practice); jp.add(menu); jp.add(bg); bg.add(logo); basic.addActionListener(this); operation.addActionListener(this); user_practice.addActionListener(this); menu.addActionListener(this); basic.setBounds(100,160,250,60); operation.setBounds(100,260,250,60); user_practice.setBounds(100,560,250,60); menu.setBounds(55,30,50,50); bg.setBounds(0,0,1300,800); logo.setBounds(700,1,850,80); text t=new text(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==menu) { main m1=new main(); this.setVisible(false); } else if(e.getSource()==basic) { basicarray m1=new basicarray(); this.setVisible(false); } else if(e.getSource()==operation) { operations m2=new operations(); this.setVisible(false); } else if(e.getSource()==user_practice) { practicearray m4=new practicearray(); this.setVisible(false); } } }
- 05-15-2012, 09:44 AM #8
Member
- Join Date
- May 2012
- Location
- Yamuna Nagar,Haryana,India
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Making my JComponent scrollable - the finer points
By kjkrum in forum AWT / SwingReplies: 7Last Post: 03-16-2012, 06:24 PM -
Making my JComponent scrollable
By kjkrum in forum AWT / SwingReplies: 4Last Post: 03-11-2012, 08:08 PM -
How do I make a JPanel (which holds images) scrollable?
By Ami in forum AWT / SwingReplies: 1Last Post: 03-03-2012, 09:35 PM -
Help making calculator with TextArea
By matrixcool in forum AWT / SwingReplies: 9Last Post: 12-15-2010, 02:56 AM -
Can't resize textarea in JPanel Form
By wiguy in forum NetBeansReplies: 0Last Post: 04-02-2009, 10:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks