Reputation: 316
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
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.
Upvotes: 1
Views: 257
Reputation: 14413
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
Upvotes: 2