Reputation: 21
I want to add a jscroll pane in a jframe that is not alone with the something it scrolls through because whenever I add a JScrollPane I must make
JScrollPane p = new JScrollPane();
p.createVerticalScrollBar();
fr.setContentPane(p);
fr.revalidate();
if I just added it It doesn't appear like:
fr.add(p);
that doesn't appear..
I don't want the scrollpane to appear alone in the frame but with other things maybe a button and a textfield..
any help would be much appreciated
Upvotes: 0
Views: 45
Reputation: 2286
public class SampleFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
createAndShowGUI();
}
});
}
public static void createAndShowGUI()
{
JFrame frame = new JFrame("JFrame with ScrollBar");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea textArea = new JTextArea(5,20);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(scrollPane);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
try This
Upvotes: 1