Solved

I want to get a JLabel At the top of the Checkbox

Posted on 2004-04-03
2
454 Views
Last Modified: 2013-11-23
I want to get a JLabel At the top of the Checkbox grouping made by Myclass4 #3.
The way it is now is on the left side and throws all of the columns off and the numbering get mixed up, the spacing gets changed as well.

HELP

#1
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class TrainerMain extends JFrame
{ //Opens TrainerMain class
 
  private JTabbedPane tabbedPane;
  private JFrame dlframe;
 

     
      public TrainerMain()
      { //Opens TrainerMain constructor
     
      //Create a frame object to add the application
      //GUI components to.
     
        dlframe = new JFrame("This is Training Arts Program");
       
        // Closes from title bar
        //and from menu
        dlframe.addWindowListener(new WindowAdapter()
        { // Opens addWindowListener method
          public void windowClosing(WindowEvent e)
          { // Opens windowClosing method
             System.exit(0);
           } // Closes windowClosing method
         }); // Closes addWindowListener method
         
                 
         // Tabbed pane with panels for Jcomponents
         
         tabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
         tabbedPane.setBackground(Color.yellow);
         tabbedPane.setForeground(Color.black);
         
         // Calls a method that adds individual tabs to the
         //tabbedpane object.
         populateTabbedPane();
         
         //Calls the method that builds the menu
         buildMenu();
         
         dlframe.getContentPane().add(tabbedPane);
         
         dlframe.pack();
         dlframe.setSize(765, 690);
         dlframe.setBackground(Color.white);
         dlframe.setVisible(true);
         } // Ends class constructor
         
         private void populateTabbedPane()
           { // Opens populateTabbedPane method definition
           // Create tabs with titles
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);
           tabbedPane.addTab("Introduction",
                               null,
                               new Introduction(),
                               "Welcome to the martial arts trainer");

                       
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);                    
           tabbedPane.addTab("Training Options",
                               null,
                               new TrainingOptions(),
                               "Click here to enter your options");
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);                  
           tabbedPane.addTab("Blocks & Hand Stricks ",
                               null,
                               new BlocksAndHandStricks(),
                               "Click here to enter blocks & hand stricks");
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);
           tabbedPane.addTab("Kicks & Stances",
                               null,
                               new KicksAndStances(),
                               "Click here to calculate dive statistics");
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);
           tabbedPane.addTab("Defensive Moves",
                               null,
                               new DefensiveMoves(),
                               "Click here to see a web site");                
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);
           tabbedPane.addTab("Kempo",
                               null,
                               new Kempos(),
                        "Click here to see a list of resources");        
           
           
           dlframe.getContentPane().setLayout(new BorderLayout());
           dlframe.getContentPane().add(tabbedPane, BorderLayout.CENTER);
           tabbedPane.addTab("Movement",
                               null,
                               new Movement(),
                               "Click here to see a list of resources");                                        
                     } //Ends populateTabbedPane method
         
         
         private void buildMenu()
         { // Opens buildMenu method definition
         
         
           // Create the menubar.  Tell the frame about it.
            // Create the menubar.  Tell the frame about it.
            JMenuBar menubar = new JMenuBar();
           

          // Create the file menu.  Add to menubar.
          JMenu file = new JMenu("File");
          menubar.add(file);

    // Create four items for the file JMenu, setting their label, shortcut,
    // action command and listener.  Add them to File JMenu.
    // The frame itself as the action listener
           JMenuItem Fnew = new JMenuItem("New");
           Fnew.setActionCommand("new");
           file.add(Fnew);
           JMenuItem open = new JMenuItem("Open");
           open.setActionCommand("open");
           file.add(open);
           JMenuItem save = new JMenuItem("Save");
           save.setActionCommand("save");
           file.add(save);
           JMenuItem close = new JMenuItem("Close");
           close.setActionCommand("close");
           file.add(close);
           JMenuItem quit = new JMenuItem("Quit");
           quit.setActionCommand("quit");
           file.add(quit);
   
           // Create the Levels JMenu.  Add to JMenubar.
            JMenu levels = new JMenu("Levels");
            menubar.add(levels);                  
              JCheckBoxMenuItem beginner = new JCheckBoxMenuItem("Beginner");
              beginner.setHorizontalTextPosition(JMenuItem.RIGHT);
              beginner.setSelected(true);
              JCheckBoxMenuItem novice = new JCheckBoxMenuItem("Novice");
              novice.setHorizontalTextPosition(JMenuItem.RIGHT);
              novice.setSelected(false);
              JCheckBoxMenuItem  intermediate = new JCheckBoxMenuItem(" Intermediate");
              intermediate.setHorizontalTextPosition(JMenuItem.RIGHT);
              intermediate.setSelected(false);
              JCheckBoxMenuItem advanced = new JCheckBoxMenuItem("Advanced");
              advanced.setHorizontalTextPosition(JMenuItem.RIGHT);
              advanced.setSelected(false);
              JCheckBoxMenuItem accomplished = new JCheckBoxMenuItem("Accomplished");
              accomplished.setHorizontalTextPosition(JMenuItem.RIGHT);
              accomplished.setSelected(false);
       
              levels.add(beginner);
              levels.add(novice);
              levels.add(intermediate);
              levels.add(advanced);
              levels.add(accomplished);

           
     
     // Create the Audio JMenu and Add to JMenubar.
            JMenu audio = new JMenu("Audio");
            menubar.add(audio);
            JMenuItem record = new JMenuItem("Record");
            record.setActionCommand("record");
            audio.add(record);
            JMenuItem play = new JMenuItem("Play");
            play.setActionCommand("play");
            audio.add(play);
            JMenuItem createcd = new JMenuItem("CreateCD");
            createcd.setActionCommand("createcd");
            audio.add(createcd);
   
           // Create Help JMenu; add an item; add to JMenubar
                     
           JMenu help = new JMenu("Help");
           menubar.add(help);
               
            // Create and add an item to the Help JMenu
            JMenuItem about = new JMenuItem("About");
            about.setActionCommand("about");

            help.add(about);
            JMenuItem aid = new JMenuItem("Help");
            aid.setActionCommand("aid");

            help.add(aid);
         
           
              dlframe.setJMenuBar(menubar);
             }// Closes buildJMenu method

 
 
 
 
// This is the action listener method that the menu items invoke

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("quit")) {
     
     YesNoDialog d = new YesNoDialog(dlframe, "Really Quit?",
                                      "Are you sure you want to quit?",
                                      "Yes", "No", null);  
      d.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          if (e.getActionCommand().equals("yes")) System.exit(0);
          }
      });
      d.show();
    }
    else if (command.equals("open")) {
      FileDialog d = new FileDialog(dlframe, "Open File", FileDialog.LOAD);
      d.show();  // display the dialog and block until answered
            d.dispose();
    }
    else if (command.equals("Save")) {
      FileDialog d = new FileDialog(dlframe, "Save File", FileDialog.LOAD);
      d.show();  // display the dialog and block until answered
            d.dispose();
    }
    else if (command.equals("about")) {
      InfoDialog d = new InfoDialog(dlframe, "About",
                                "This demo was written by David Flanagan\n" +
                                "Copyright (c) 1997 O'Reilly & Associates");
      d.show();
    }
  }

 
 
 

  // main method and entry point for app    
     public static void main(String[] args)
     { // Opens main method
     
      TrainerMain dl = new TrainerMain();
     
     
      } // Closes main method
}      

 
                             
                               
               

#2  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BlocksAndHandStricks extends JPanel
{ // Opens class

    JPanel jPanel1;
    JPanel jPanel1A;
    JPanel jPanel1B;
    JPanel jPanel1C;
    JPanel jPanel2;
    JPanel jPanel2A;
    JPanel jPanel2B;
    JPanel jPanel2C;
    JPanel jPanel3;
    JPanel jPanel4;

    JLabel jLabel1;
    JLabel jLabel2;
    JLabel jLabel3;
    JLabel jLabel4;
    JLabel jLabel5;
    JLabel jLabel6;
    JLabel jLabel7;
    JLabel jLabel8;
    JLabel jLabel9;
    JLabel jLabel10;
    JLabel jLabel11;
    JLabel jLabel12;
   

    public BlocksAndHandStricks()
    {
        super();

Font f1 = new Font("Courier New", Font.BOLD, 15);

jPanel1 = new javax.swing.JPanel();
jPanel1A = new javax.swing.JPanel();
jPanel1B = new javax.swing.JPanel();


jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jPanel2A = new javax.swing.JPanel();
jPanel2B = new javax.swing.JPanel();
jPanel2C = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();

setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
jPanel1.add(Box.createGlue());

add(jPanel1);
jPanel1.add(jPanel1A);
jPanel1.add(jPanel1B);
jPanel1A.setBorder(BorderFactory.createLoweredBevelBorder());
jPanel1B.setBorder(BorderFactory.createRaisedBevelBorder());


jPanel1A.add(new MyClass4());
jPanel1B.add(new MyClass4());


add(jPanel2);
jPanel2.add(Box.createGlue());
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
jPanel2.setBorder(BorderFactory.createLoweredBevelBorder());

jPanel2.add(jLabel4);




   
    }
}


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


public class MyClass4 extends JPanel {

  JLabel jLabel = new JLabel();
  ArrayList myArrayList = new ArrayList();

public MyClass4() {

     // Call it like this . . .
     
    setLayout(new GridLayout(0,3));// Setting MY layout...
 
    add(jLabel);  
    jLabel.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);
    }
    }
}
}

0
Comment
Question by:Drop_of_Rain
  • 2
2 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 175 total points
Comment Utility
you need an additional JPanel:

public MyClass4() {

     // Call it like this . . .
    JPanel gridPanel = new JPanel(new GridLayout(0,3));// Setting MY layout...
    setLayout(new BorderLayout());
    add(jLabel, BorderLayout.NORTH);
    add(gridPanel, BorderLayout.CENTER);

    jLabel.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);
        gridPanel.add(check);
      }
    }
}
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
Comment Utility
:°)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

744 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

15 Experts available now in Live!

Get 1:1 Help Now