| Author |
Problem with scroll
|
danesh far
Greenhorn
Joined: Nov 25, 2004
Posts: 15
|
|
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); } }
|
 |
Kriti Garg
Ranch Hand
Joined: Sep 13, 2004
Posts: 50
|
|
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
|
 |
Gurumurthy Ramamurthy
Ranch Hand
Joined: Feb 13, 2003
Posts: 272
|
|
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); } }
|
 |
 |
|
|
subject: Problem with scroll
|
|
|