How to determine the size of a Jtextfield?

Asked

Viewed 1,709 times

0

I’m doing a program involving the Pitgora theorem, and I’d like to leave a triangle in the middle, with three Jtextfields around the three sides of it. I did that, but the problem is that when I create Jtextfield and add it to the desired Container, it gets huge. It’s a very large white rectangle that when I click to type, comes out a small letter. So my question is: How can I change the size of this Jtextfield to decrease it and avoid unnecessary sizes?

  • NOTE: I am using the Swing library and AWT same!!

  • What is the Layout of your Jtextfield content pane? Example: Borderlayout, Miglayout, Gridbaglayout...

1 answer

-1


Try to use the setBounds, see here.

Example:

public void teste()
    {
        //posição da caixa de texto no eixo horizontal em pixeis 
        int posX = 10;

        //posição da caixa de texto no eixo vertical em pixeis 
        int posY = 10;

        //largura da caixa de texto em pixeis
        int largura = 10;

         //altura da caixa de texto em pixeis
        int altura = 10;
        //é necessário instanciar antes o objecto
        JTextField cxaTexto = new JTextField();

        cxaTexto.setBounds(posX, posY, largura, altura);
    }
  • 3

    Try posting a practical example in code using your solution, not just posting a reference

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed.

  • In my opinion posting an example will make it unnecessary to put the reference and vice versa, but there are no makas, I will update the reply bro.

  • 2

    @Caputo, thank you for the explanation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.