Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need Label on top of Jpanel

Posted on 2004-04-02
5
Medium Priority
?
180 Views
Last Modified: 2012-05-04
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
}
}
}
}
0
Comment
Question by:Drop_of_Rain
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 10746605
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



0
 

Author Comment

by:Drop_of_Rain
ID: 10746637
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.
0
 
LVL 15

Accepted Solution

by:
Javatm earned 300 total points
ID: 10746646
Then you need to declare a layout like :

setLayout(new GridLayout(2,1));
add(jLabel1); add(jLabel2);

If your adding the JPanel to a JFrame then your need :
this.getContentPane().add(MyClass4, BorderLayout.CENTER);

If you have any questions just let me know !
Friend : Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10961249
Thanks for the support,
Christopher
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question