subhro
asked on
could not view components....
this is a code which i wrote using swing ....
CODE:
-------------------------- --------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldDemo1 extends JFrame {
public Container container;
JTextField textfield1,textfield2;
public TextFieldDemo1() {
container= this.getContentPane();
container.setLayout(new BoxLayout(container,BoxLay out.Y_AXIS ));
textfield1=new JTextField("",20);
textfield1.addActionListen er(new TextFieldListener());
textfield1.setBorder(Borde rFactory.c reateLineB order(Colo r.black));
textfield2=new JTextField();
textfield2.setBorder(Borde rFactory.c reateLineB order(Colo r.black));
JButton button=new JButton("Clear");
button.addActionListener(n ew ButtonListener());
container.add(Box.createVe rticalGlue ());
container.add(textfield1);
container.add(Box.createVe rticalGlue ());
container.add(textfield2);
container.add(Box.createVe rticalGlue ());
container.add(button);
container.add(Box.createVe rticalGlue ());
}//end constructor
class TextFieldListener implements ActionListener{
public void actionPerformed(ActionEven t e){
textfield2.setText(e.getAc tionComman d());
}
}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEven t e){
textfield1.setText("");
textfield1.requestFocus();
textfield2.setText("");
}
}
public static void main(String args[]){
TextFieldDemo1 text=new TextFieldDemo1();
text.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
text.setTitle("Text Field Demo");
text.setSize(300,400);
text.setVisible(true);
}//end main
}
-------------------------- --------
now the problem is that even if i have given the
createVerticalGlue() ...... it does not give any space between the textfields .. which results in a very wide textfields ....
how can i leave some space in between the textfields and button...???
thanx ..subhro
and
CODE:
--------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldDemo1 extends JFrame {
public Container container;
JTextField textfield1,textfield2;
public TextFieldDemo1() {
container= this.getContentPane();
container.setLayout(new BoxLayout(container,BoxLay
textfield1=new JTextField("",20);
textfield1.addActionListen
textfield1.setBorder(Borde
textfield2=new JTextField();
textfield2.setBorder(Borde
JButton button=new JButton("Clear");
button.addActionListener(n
container.add(Box.createVe
container.add(textfield1);
container.add(Box.createVe
container.add(textfield2);
container.add(Box.createVe
container.add(button);
container.add(Box.createVe
}//end constructor
class TextFieldListener implements ActionListener{
public void actionPerformed(ActionEven
textfield2.setText(e.getAc
}
}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEven
textfield1.setText("");
textfield1.requestFocus();
textfield2.setText("");
}
}
public static void main(String args[]){
TextFieldDemo1 text=new TextFieldDemo1();
text.addWindowListener(new
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
text.setTitle("Text Field Demo");
text.setSize(300,400);
text.setVisible(true);
}//end main
}
--------------------------
now the problem is that even if i have given the
createVerticalGlue() ...... it does not give any space between the textfields .. which results in a very wide textfields ....
how can i leave some space in between the textfields and button...???
thanx ..subhro
and
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanx ... actually that is what i did after i had posted the question .. it did work ... but the question still remains why .. createVerticalGlue does not work ....
anyways thanx .... subhro
anyways thanx .... subhro
its work when textarea have fixed size
http://java.sun.com/docs/books/tutorial/uiswing/layout/problems.html
http://java.sun.com/docs/books/tutorial/uiswing/layout/generalRules.html
try use .add(Box.createRigidArea(n