Hello,
I write a swing program in which there are three check boxes(used images in check boxes). When I click any check box then- which check box is clicked is displayed in the text field. When I run the program then I can't see all the images. I wanna use a scrollbar so that I can see the entire output. I use JScrollPane in the program but it isn't working.
here is the code------
Please help me out...
thanks....
I write a swing program in which there are three check boxes(used images in check boxes). When I click any check box then- which check box is clicked is displayed in the text field. When I run the program then I can't see all the images. I wanna use a scrollbar so that I can see the entire output. I use JScrollPane in the program but it isn't working.
here is the code------
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;
/* <applet
code=jcb_i.class
width=600
height=600
>
</applet> */
public class jcb_i extends JApplet
{
jpanel j;
public void init()
{
Container c=getContentPane();
c.setBackground(Color.black);
c.setForeground(Color.white);
j=new jpanel(new GridLayout(4,1));
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane jsb=new JScrollPane(j,v,h);
c.add(jsb);
}
}
class jpanel extends JPanel implements ItemListener
{
ImageIcon ankita,anurag;
JCheckBox b1,b2,b3;
JTextField jtf;
jpanel(LayoutManager layout)
{
ankita=new ImageIcon("ankita.jpg");
anurag=new ImageIcon("anurag.jpg");
b1=new JCheckBox("ankita 1",ankita);
b2=new JCheckBox("ankita 2",ankita);
b3=new JCheckBox("ankita 3",ankita);
b1.setSelectedIcon(anurag);
b2.setSelectedIcon(anurag);
b3.setSelectedIcon(anurag);
jtf=new JTextField(50);
jtf.setFont(new Font("castellar",Font.PLAIN,20));
jtf.setHorizontalAlignment(jtf.CENTER);
b1.addItemListener(this);
b2.addItemListener(this);
b3.addItemListener(this);
add(b1);
add(b2);
add(b3);
add(jtf);
}
public void itemStateChanged(ItemEvent e)
{
jtf.setText("You click : "+((JCheckBox) e.getItemSelectable()).getText());
}
}
thanks....
Comment