I have a JTextpane where i will be adding instructions. I know this will not be large enough, but there is no further space on my interface, so I need to add either a scrollbar or scrollpane.
I have tried a few attempts at this but cannot get either to appear. Can anyone help me with this?
Should I be using a scrollbar or scrollpane for a textpanel?
I just need it so the user can scroll down the text which isn't visible.
instructionTextPanel = new javax.swing.JTextPane(); 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(instructionTextPanel); 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); getContentPane().add(instructionPanel);
I did read somewhere that the scrollbars will appear when the preferred size of the panel is greater than the size of the pane, but couldn't set this up.
Is it that I should use a JTextArea instead of a JTextPane?
Any pointers would be appreciated :)