Solved

Need Label on top of Jpanel

Posted on 2004-04-02
5
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

626 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