Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

scrollpane and panels  RSS feed

 
vidya archana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone please help me out in this problem?
i cant giev a scoll to the panel. and even this simple code is not working..
Please help.
JFrame fr = new JFrame();
Container c = fr.getContentPane();

JPanel p = new JPanel(null);
JPanel pp = new JPanel();

// adding a textfield to panel p
JTextField a = new JTextField();
a.setBounds(80, 50, 250, 28);
a.setHorizontalAlignment(JTextField.RIGHT);
p.add(a);


// adding panel p to scrollpane
JScrollPane scroll = new JScrollPane(p,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setBounds(120,0,100,200);

// scrollpane is added to panel pp
pp.add(scroll);


//add panel pp to frame
c.add(pp);
fr.setSize(250,200);
fr.show();
 
Amol Desai
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your code works after adding the following to JScrollPane
scroll.setPreferredSize(new Dimension(100,100));
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!