Replace the line
instructionPanel.add(instructionTextPanel);
with
instructionPanel.add(slider);
The scrollpaneslider was created to wrap the textpane. You must add that object to the panel not the original text pane.
Are you sure you want this JTextPane to be disabled?
For more help, www.NeedProgrammingHelp.com
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1
This is the code that works when I changed the line. Run the code below.
import javax.swing.*;
import java.awt.*;
class TextPane
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
JPanel instructionPanel = new JPanel();
jf.setLayout(null);
JTextPane instructionTextPanel = new javax.swing.JTextPane();
JScrollPane slider = new JScrollPane(instructionTextPanel);
// instructionTextPanel.add(slider);
//slider.addAdjustmentListener(this);
instructionTextPanel.setFont(new java.awt.Font("MS Sans Serif", 1, 14));
instructionTextPanel.setText("instructions will go in here!");
instructionPanel.add(slider);
// instructionTextPanel.disable();
instructionTextPanel.setBounds(6,7,175,179);
instructionTextPanel.setBorder(new javax.swing.border.TitledBorder(null, "Instructions", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 16), new java.awt.Color(0, 102, 102)));
instructionPanel.setBounds(0,0,190,260);
jf.getContentPane().add(instructionPanel);
jf.setBounds(100,100,400,300);
jf.setVisible(true);
}
}
Maybe it is showing but the size of the scroll pane ends up being much too small. Try to set the bounds of it.
slider.setBounds(6,7,175,179);
For more help, www.NeedProgrammingHelp.com
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1