Solved

Need Label on top of Jpanel

Posted on 2004-04-02
5
169 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 75 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now