• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with scroll

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am writing an application to show a scroll panel attached to a text area
but it does not appear on the screen. If remove the lines

JScrollPane scrollText = new JScrollPane(textArea);
contentPane.add(scrollText);
and add
contentPane.add(textField)
It appears but without scroll?.


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

class TestFrame extends JFrame {
private JTextArea textArea;

public static void main(String[] args) {
TestFrame frame = new TestFrame();
frame.setVisible(true);
}

public TestFrame( ) {

setSize ( 700, 400 );
setLocation ( 5, 5 );

Container contentPane = getContentPane();
contentPane.setBackground(Color.white);
contentPane.setLayout(null);

textArea = new JTextArea();
textArea.setEditable(false);
textArea.setBounds(350, 50, 100, 135);
textArea.setBorder(BorderFactory.createLineBorder(Color.red));
JScrollPane scrollText = new JScrollPane(textArea);
contentPane.add(scrollText);

}



}
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

problem lies in the line

contentPane.setLayout(null); //remove this line

and as your text area is uneditable ,scrollbar will not be added when typed sufficient characrted add this for ahieving that

scrollText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);


scrollText.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);


hope it will help u out!
BBye

Kriti
 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Final Code:
import javax.swing.*;
import java.awt.*;

class TestFrame extends JFrame {
private JTextArea textArea;

public static void main(String[] args) {
TestFrame frame = new TestFrame();
frame.setVisible(true);
}

public TestFrame() {
Container contentPane = getContentPane();
contentPane.setBackground(Color.white);

textArea = new JTextArea();
JScrollPane scrollText = new JScrollPane(textArea);
scrollText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(scrollText);
setSize(700,400);
setLocation(5,5);

}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic