hidding components problem
Hi
i have a text area and button in my applet.
the text area initially not visible
when pressing the button the text area will be visible
when the button is pressed again the text area will not be visible and so on.
this is a part of my code:
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
publicclass showHideextends JApplet{
TextArea area;
Labellb;
JPanel textarea ;
JPanel label_panel;
JPanel button_textArea_panel;
JPanel buttonsPanel;
JButton Start;
boolean pressed =false;
publicvoid init(){
label_panel =new JPanel();
label_panel.setLayout(new BorderLayout());
label_panel.add(new Label("show/ hide textArea ",Label.CENTER));
textarea =new JPanel();
textarea.setLayout(new FlowLayout(FlowLayout.RIGHT));
textarea.setBackground(new Color(228, 241, 250));
area =new TextArea(5,20);
area.setVisible(false);
textarea.add("Center", area);
Start =new JButton(" show text area");
Start.addActionListener(new StartListener());
buttonsPanel =new JPanel();// i used Panel because i have many buttons
buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
buttonsPanel.add(Start);
button_textArea_panel =new JPanel();
button_textArea_panel.setLayout(new FlowLayout(FlowLayout.CENTER));
button_textArea_panel.add(buttonsPanel);
button_textArea_panel.add(textarea);
this.setLayout(new BorderLayout());
add("North",label_panel);
add("South",button_textArea_panel);
}
privateclass StartListenerimplements ActionListener{
publicvoid actionPerformed(ActionEvent e){
if(pressed ==true)
{
area.setVisible(false);
Start.setLabel("show text area");
pressed=false;
}
else
{
area.setVisible(true);
Start.setLabel("Hide text area");
pressed=true;
}
}// end actionPerformed
}// end class StartListener
}
every thing is working correctly but,
the Problem is:
How to make the text area place preserved and the button position fixed,so that the button will not move when showing and hiding the text area?

