Hello , I have written a code in java using swing.So that i will have a JscrollPane added to JPanel n then I will add buttons of fixed size to JPanel in verticle fashion
JPanel panel=new JPanel();
panel.setBackground(Color.WHITE);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane jsp=new JScrollPane(panel,v,h);
jsp.setPreferredSize(new Dimension(600,600));
jsp.setBounds(150,670,850,200);
frame.add(jsp);
then I am adding buttons to it at run time.
for(i=0;i<n;i++)
{
button[i]=new JButton();
button[i].setBounds(20,y,120,120);
button[i].setSize(120,120);
button[i].setToolTipText(file[i].toString());
button[i].setIcon(Icon);
panel.add(button[i]);
y=y+140;
}
I want to add a button one below another...(i.e I wnt a verticle scrollbar)
i.e. button1
button2
'
'
and above code is giving me buttons in a line (i.e. I am getting horizontal scrollbar) i.e. button1 button2 . . .
another problem is the size of button I am setting using setsize is not affecting button size at all...
can anybody help me???