Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need Label on top of Jpanel

Posted on 2004-04-02
5
Medium Priority
?
179 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

688 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