JApplet ,JScrollPane, JPanel
Hi,
I have a class JTestPanel2 which extends JPanel, I have added a button to this class and overriden the paint method to draw some lines,
In my JApplet, i create instance of Test class and add to the JSCrollPane, I add this JScrollPane to my JApplet content pane, the problem is i dont see the JButton on the screen , but when i click on some where i have added the JButton , i get the action performed event triggered,
My layout for Test class is BorderLayout and i add the button to north,
So what is the problem ..how can i solve it,
Answere ASAP
here is the code
for JPAnel
//**************
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JPanelTest2 extends JPanel implements ActionListener
{
JPanel jp2 ;
JButton jb;
String message = "test";
JPanelTest2()
{
super();
setLayout(new BorderLayout());
jp2 = new JPanel();
jb = new JButton("Okay");
jb.addActionListener(this);
jp2.add(jb);
setPreferredSize(new Dimension(400,400));
add("North", jp2);
jp2.setVisible(true);
}
public void paint(Graphics g)
{
super.paintComponent(g);
g.drawString(message, 200, 200);
}
public void actionPerformed(ActionEvent ev)
{
message = "change";
repaint();
}
}
Code for Applet
//*********
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JPanelTest1 extends JApplet
{
Container c ;
public void init()
{
c = getContentPane();
c.setLayout(new BorderLayout());
JPanelTest2 jp1= new JPanelTest2();
JScrollPane js = new JScrollPane(jp1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
js.getHorizontalScrollBar().setMaximum(500);
js.getHorizontalScrollBar().setValue(0);
setSize(400,400);
c.add("North", js);
}
}
Ashish

