Focus no textfield e fixar tamanha no gridbaglayout

0 respostas
T

Olá pessoal

tenho 2 problemas: quero iniciar o com o cursor “marcado” no textfield (txta), já tentei requestFocus(); grabFocus(); e não deu certo, o button help q começa “marcado” (aparece uma “borda” nele). O outro é no GridBagLayout, quero q os componentes não se mexam msm se o q tiverem dentro for maior, tentei cons.fill = GridBagConstraints.NONE; mas se sucesso.

public class applet2 extends JApplet{
   DrawPanel panel;
   DrawControls controls;
   double delay;
   boolean pleasewait = false;
   Image offscreenImage=null;
    Graphics offscreengraphics=null;
    double pi = 3.1416;

   public void init() {
   setLayout(new BorderLayout());
   panel = new DrawPanel(null);
       controls = new DrawControls(panel);
   add("Center", panel);
   add("South",controls);

   }

   public void destroy() {
       remove(panel);
       remove(controls);
   }

   public static void main(String args[]) {

   JFrame f = new JFrame("Pêndulo tipo mola");
    applet2 drawTest = new  applet2();
   drawTest.init();
   drawTest.start();

       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.add("Center", drawTest);
   f.setSize(500, 500);
   f.setVisible(true);

   }


class DrawControls extends JPanel implements ActionListener {


 private Button help = new Button("?");

    private JTextField txta = new JTextField("0.5",3);
   


    DrawPanel tread;

String get_a, get_w,get_t,get_f,get_k;

double a,w,te,k,f, calc_v, calc_x, calc_a;




   public DrawControls(DrawPanel target) {

        tread = target;
       boolean flaglbl = false;

    GridBagConstraints cons = new GridBagConstraints();
       GridBagLayout layout = new GridBagLayout();

       JPanel panel = new JPanel(layout);

       cons.fill = GridBagConstraints.NONE;
       cons.gridy = 0;        cons.gridx = 0;

      panel.setPreferredSize(new Dimension(505,180));
   setBackground(Color.lightGray);


     cons.gridx = 0; cons.gridy = 0; cons.gridwidth = 2;
      panel.add(pend, cons);

      cons.gridwidth = 1;
  cons.gridx = 3; cons.gridy = 0;
      panel.add(help, cons);

    


       
       cons.gridx = 0; cons.gridy = 2;
      panel.add(lbla, cons);
      cons.gridy = 2;        cons.gridx = 1;
      panel.add(txta, cons); 
      cons.gridy = 2;        cons.gridx = 2;
      panel.add(m, cons);



      cons.gridx = 4; cons.gridy =6;
     panel.add(lblet, cons); lblet.setVisible(false);// cons.fill = GridBagConstraints.NONE;
     cons.gridx = 5; cons.gridy = 6; 
   panel.add(resposta,cons);


    panel.setBackground(Color.lightGray);
         setLayout(new BorderLayout());
     add("South", panel);



help.addActionListener(this);
      vrbutton.addActionListener(this);
       erbutton.addActionListener(this);
        trbutton.addActionListener(this);



     }

   public String get_txta(){
    return txta.getText( );
   }





    public void actionPerformed(ActionEvent e) {
        

       if(e.getSource()==help){
         // construção da janela 
       teoria janela = new teoria();
       janela.setSize(640,480);
       janela.setVisible(true);
     }
Criado 24 de julho de 2011
Respostas 0
Participantes 1