Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

Need Label on top of Jpanel

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyClass4 extends JPanel {
 
 
  ArrayList myArrayList = new ArrayList();

// Constructor
public MyClass4() {

    setLayout(new GridLayout(0,3)); // Setting MY layout...
JLabel jLabel1 = new JLabel();  
add(jLabel1);  jLabel1.setText("Defensive Moves"); setBackground(Color.white);

    looprow:
        for (int row=0; row<20; row++) {
            for(int col=0; col<3; col++) {
                int n=(20*col+row+1);
                if (n>50) break looprow;
                JCheckBox check = new JCheckBox("" + n);

            myArrayList.add(check);
add(check); // Adding it to ME
}
}
}
}
Avatar of Javatm
Javatm
Flag of Singapore image

Create another label and add it to the panel like :

// Here is the new JLabel . . .
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();

add(jLabel1); add(jLabel1);

jLabel1.setText("Defensive Moves");
setBackground(Color.white);

Hope that helps . . .
Javatm



Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

That isn't creating what I need. I need it to be in the top center. It is in the left top corner but is changing the layout of thr columns.
ASKER CERTIFIED SOLUTION
Avatar of Javatm
Javatm
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the support,
Christopher