Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i give a Jlable container a layout manager? I tried to set it this way :

lab1=new JLabel(new GridLayout(1,1,15,15));


But it says this constructor is undefined. Can anyone help me with this?
Posted

1 solution

The code snippet below creates the GridLayout object and the components it manages.


GridLayout experimentLayout = new GridLayout(0,2);

...

compsToExperiment.setLayout(experimentLayout);

compsToExperiment.add(new JButton("Button 1"));
compsToExperiment.add(new JButton("Button 2"));
compsToExperiment.add(new JButton("Button 3"));
compsToExperiment.add(new JButton("Long-Named Button 4"));
compsToExperiment.add(new JButton("5"));

or

GridLayout experimentLayout = new GridLayout(0,2);


compsToExperiment.setLayout(experimentLayout);
lab1=new JLabel("MyLabel");
compsToExperiment.add(lab1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900