Pergunta

I have a JTextField called jta in my java program and i want it to be about 4 rows tall and I set the size when I declared the TextField and i also used jta.setSize() but I still cannot get it taller. I think it is because the MigLayout has a limit for how big a component can be in a row.

Here is a snippit of my code:

static JTextArea jta = new JTextArea(10, 42);
//declaring the JTextArea
    jta.setFont(inputfont);
    jta.setBackground(Color.LIGHT_GRAY);
    jta.setForeground(Color.WHITE);
    jta.setLineWrap(true);
    jta.setWrapStyleWord(true);
    jta.setRows(4);
//setting the jta up
panel.add(jta,"w 100%, h 100%,span,wrap");\
//adding jta to the panel

Here Is What It Looks Like

enter image description here

as you see it is only one line of text high, any help?

SSCCE:

import net.miginfocom.swing.MigLayout;

public class miglayout {

public static void main(String args[]) {
    MigLayout mg = new MigLayout("", "", "1");
    JFrame frame = new JFrame("jta SSCCE");
    JPanel panel = new JPanel();
    JLabel l1 = new JLabel("Row 1");
    JLabel l2 = new JLabel("Row 3");
    panel.setLayout(mg);
    frame.add(panel);
    JTextArea jta = new JTextArea(4, 40);
    panel.add(l1, "wrap");
    panel.add(jta, "wrap");
    panel.add(l2);
    frame.pack();
    frame.setVisible(true);
    }
}

As you can see if you run this code, even though I set the size of the JTextArea it is still one line, but if you comment out the panel.setLayout(mg); then it works fine.

Foi útil?

Solução

Im not an expert using this layout but thanks you post a SSCCE.

if you change

MigLayout mg = new MigLayout("", "", "1");

to

MigLayout mg = new MigLayout();

I get

migLayout

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top