aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JVeiwporterror Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JVeiwporterror" Watch "JVeiwporterror" New topic
Author

JVeiwporterror

nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
hi
i hve following code prgram working good
but component not visible which are scrolled
how can i scroll them help


import java.awt.*;
import javax.swing.*;
import java.net.*;
import java.awt.event.*;


class SDemo2
{
static JScrollBar sv;
static JPanel p;
static JViewport jvp;


public static void main(String a[])




{

JScrollPane j ;
jvp=new JViewport();
sv =new JScrollBar(JScrollBar.VERTICAL,0,0,0,600);
p=new JPanel();

p.setLayout(null);

JFrame f=new JFrame();
JButton b[]=new JButton[100];
//JTextField b[]=new JTextField[90];
int y=10;

for(int i=0; i<15; i++)
{
b[i]=new JButton("High");

b[i].setBounds(10,y,100,50);
y=y+40;

p.add(b[i]);
}



jvp.add(p);
f.getContentPane().add(jvp,BorderLayout.CENTER);
f.getContentPane().add(sv,BorderLayout.EAST);


f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);
f.setSize(500,500);


sv.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged( AdjustmentEvent e)
{

JScrollBar h=(JScrollBar)e.getSource();


Point pt=jvp.getViewPosition();
pt.y=e.getValue();

jvp.setViewPosition(pt);


}});



}




}
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Ususally if some action manages to make a component
whose setVisible method has been called (with true as the argument),
invisible, calling setSize (i.e. setSize(100,100)) will force the entire componentto become visible.

Its kind of a hack but always seems to work for me.
 
jQuery in Action, 2nd edition
 
subject: JVeiwporterror