Why do I get Illegal Component position when I say FlowLayout.CENTER

The code runs fine if you replace the line
Jp7.add(submitButton, FlowLayout.CENTER);
with
Jp7.add(submitButton);
I know FlowLayout's default location is CENTER. But when I explicitly say to center the button, it crashes during runtime but compiles fine.
Whats the reason for this? Is this a bug?
I am using 1.4.0_03.
I getthe following error.
Exception in thread "main" java.lang.IllegalArgumentException: illegal component
position
at java.awt.Container.addImpl(Container.java:568)
at java.awt.Container.add(Container.java:327)
at Mon2.main(Mon2.java:114)
ALSO CAN I DO THE SAME WITHOUT USING SO MANY JPANELS?????????????????? I AM NOT NEW TO PROGRAMMING BUT I AM NEW TO GUI PROGRAMMING.
Thanks in advance.
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Mon2 extends JFrame{
static long i =0;
static int jobid = 0;
static String StartTime = "";
static String LastReport = "";
static String FinishTime = "";
static String Description = "";
static String job_position = "";
static String desc ="";
public static String database = "";
public static String user = "";
public static String password = "";
static int counter = 1;
static boolean valuesEntered = false;
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  BorderLayout borderLayout1 = new BorderLayout();
  JLabel jLabel1 = new JLabel();
JTextPane jTextArea1 = new JTextPane();
static JTextField userArea = new JTextField();
static JPasswordField passArea = new JPasswordField();
static JTextField databaseArea = new JTextField();     
static JFrame f = new JFrame();
static JLabel us = new JLabel ("UserName: ");
static JLabel pa = new JLabel ("Password: ");
static JLabel da = new JLabel ("Database: ");
  BorderLayout borderLayout2 = new BorderLayout();
  JPanel jPanel1 = new JPanel();
  JLabel jLabel2 = new JLabel();
     public Mon2() {
    try  {
      jbInit();
    catch (Exception e) {
      e.printStackTrace();
     public static void main(String args[]) {
          System.out.println("Starting Mon2...");
    f.setSize(300,200);
    f.setTitle("Login");
    f.setLocation(250,250);
    f.setResizable(false);
    Panel Jp1 = new Panel (new BorderLayout());
    Panel Jp3 = new Panel (new BorderLayout());
    Jp3.add(us, BorderLayout.NORTH);
    Jp3.add(pa, BorderLayout.CENTER);
    Jp3.add(da, BorderLayout.SOUTH);
    userArea.setEditable(true);
    userArea.setSize(20,20);
    passArea.setEditable(true);
    databaseArea.setEditable(true);
    JButton submitButton = new JButton("Submit");
    JPanel Jp2 = new JPanel (new BorderLayout());
    JPanel Jp4 = new JPanel (new FlowLayout());
    userArea.setPreferredSize(new Dimension(200,21));
    Jp4.add(userArea, FlowLayout.LEFT);
    Jp4.add(us, FlowLayout.LEFT);
    JPanel Jp5 = new JPanel (new FlowLayout());
    passArea.setPreferredSize(new Dimension(200,21));
    Jp5.add(passArea,FlowLayout.LEFT);
    Jp5.add(pa, FlowLayout.LEFT);
    JPanel Jp6 = new JPanel (new FlowLayout());
    databaseArea.setPreferredSize(new Dimension(200,21));
    databaseArea.setText("DWPROD");
    Jp6.add(databaseArea,FlowLayout.LEFT);
    Jp6.add(da, FlowLayout.LEFT);
    Jp1.add(Jp4, BorderLayout.NORTH);
    Jp1.add(Jp5, BorderLayout.CENTER);
    Jp2.add(Jp6, BorderLayout.NORTH);
   JPanel Jp7 = new JPanel(new FlowLayout());
///////////////////////////This is  the line//////////////////
//If you remove the ,FlowLayout.CENTER it works fine.
//If you leave it like as it is, it will compile but then give runtime error
    Jp7.add(submitButton, FlowLayout.CENTER);
    Jp2.add(Jp7, BorderLayout.SOUTH);
    Jp1.add(Jp2, BorderLayout.SOUTH);
    f.getContentPane().add(Jp1);
    Image img = Toolkit.getDefaultToolkit().getImage("c:\\appletHeader.gif");
    f.setIconImage(img);
    f.setDefaultCloseOperation(3);
    f.setVisible(true);
    f.pack();
     submitButton.resize(75, 30);
    submitButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    user = userArea.getText();
    password = passArea.getText();
    database = databaseArea.getText();
    if((user.equals(null) || password.equals(null) || database.equals(null) || user.equals("") || password.equals("") || database.equals(""))){
    valuesEntered = false;
    else{
         valuesEntered = true;
    if(valuesEntered == true){
    f.setVisible(false);
          Mon2 mainFrame = new Mon2();
          mainFrame.setSize(600, 400);
          mainFrame.setTitle("Monitor");
    mainFrame.setLocation(100,200);
    mainFrame.setResizable(false);
    desc = "ERROR! or there are no locked jobs.";
          mainFrame.setVisible(true);
    else{
    JOptionPane.showMessageDialog(null,"Must enter values for UserName, Password and Database", "Value Required",JOptionPane.INFORMATION_MESSAGE);
//    System.exit(0);
  private void jbInit() throws Exception {
    this.setDefaultCloseOperation(3);
    jButton1.setText("Refresh");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
      jButton1_actionPerformed(e);
    jButton2.setText(" Exit ");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
    this.getContentPane().setLayout(borderLayout1);
    jButton3.setText("Clear");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jTextArea1.setText("Click on Refresh to update screen.");
    Panel p = new Panel(new FlowLayout());
    Panel p2 = new Panel (new BorderLayout());
    jLabel1.setText("Monitor for current Job");
    jTextArea1.setPreferredSize(new Dimension(8, 50));
    jTextArea1.setContentType("text/html");
    jTextArea1.setText("");
    jTextArea1.setEditable(false);
    f.setResizable(false);
    f.setTitle("Login");
    jLabel2.setHorizontalTextPosition(SwingConstants.LEFT);
    jLabel2.setText("jLabel2");
    jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
    f.getContentPane().setLayout(borderLayout2);
    jTextArea1.setSize(100,10);
    p.add(jButton1);
    p.add(jButton3);
    p.add(jButton2);
    this.getContentPane().add(jLabel1, BorderLayout.NORTH);
    this.getContentPane().add(jTextArea1, BorderLayout.CENTER);
    p2.add(p, BorderLayout.CENTER);
    this.getContentPane().add(p2, BorderLayout.SOUTH);
    pack();
    f.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jLabel2, null);
  void jButton1_actionPerformed(ActionEvent e){
        jTextArea1.setText("Refreshing...");
        long i = 0;
     try{
          jTextArea1.setText("In side try block");
                Thread.sleep(1000);
               DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
               jTextArea1.setText("DriverManager");
              Connection conn=
               DriverManager.getConnection("jdbc:oracle:thin:@machine:1234:"+ database, user, password);
                                                                      jTextArea1.setText("Got COnnection");
               Statement stmt = conn.createStatement();
               jTextArea1.setText("Statement Created");
               ResultSet rs =
               stmt.executeQuery("select 1, sysdate, sysdate, sysdate, sysdate, sysdate from dual ");
               jTextArea1.setText("Query Executed");
               while(rs.next()){
      jobid = rs.getInt(1);
      StartTime = rs.getString(2);
      LastReport = rs.getString(3);
      FinishTime = rs.getString(4);
      Description = rs.getString(5);
      job_position = rs.getString(6);
      desc = "<b>Count: </b>" + counter + "" +
                 "<p><table border = '1'><tr><td><b>JOB ID:      </b></td><td>" + jobid + "</td></tr>" +
             "<tr><td><b>Start Time:  </b></td><td>" + StartTime + "</td></tr>" +
             "<tr><td><b>Last Report: </b></td><td>" + LastReport + "</td></tr>" +
             "<tr><td><b>FinishTime:  </b></td><td>" + FinishTime + "</td></tr>" +
             "<tr><td><b>Description: </b></td><td>" + Description + "</td></tr>" +
             "<tr><td><b>Position:    </b></td><td>" + job_position + "</td></tr></table>";
              counter = counter + 1;
                 rs.close();
               conn.close();
                jTextArea1.setText("Sleeping");
                jTextArea1.setText(desc);
                desc = "";
          catch (SQLException se){
          jTextArea1.setText(desc + se);
       catch(Exception ee){
            jTextArea1.setText("Exception occured\n\n" + ee);
}

Get your basics checked.
Go to:
http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html#whatAreLMs
And find the heading: FlowLayout Variations
FlowLayout can be customized at construction time by passing the
constructor an alignment setting:
FlowLayout.CENTER (the default)
FlowLayout.RIGHT
FlowLayout.LEFT

Similar Messages

  • Illegal component position when add JLabel to JtextPane

    Hi all,
    I want to add a JLabel to a JTextPane, the label shoud be put in the lines of text just like the normal text. I have some questions:
    1. How can I put the label in the position we want, when I use the method add(label, textPane.getStyledDocument().getLength()), it generates exception :"illegal component position"
    2. How can I set the width and the height of the label so that user cannot know that I used the label. I mean the text on label and the normal text on JTextPane must look the same. Of course I know the length of the caption of the label
    Thank you very much

    How can I put the label in the position we want, I'm not sure you can add a component using that method. I think there is an insertComponent(...) method to use. Also you may need to make the text pane uneditable first if I remember correctly. Something like:
    textPane.setEditable(false);
    textPane.insertComponent(...);
    textPane.setEditable(true);
    How can I put the label in the position we want, label.setFont(textPane.getFont());

  • Illegal component position error

    Hi I'm new to GUI's and I'm trying to add a menu bar onto my jframe for a creation of a word processor. I'm using the Jtextarea for the text field. I keep getting this message but dont understand what it means:
    java.lang.IllegalArgumentException: illegal component position
    at java.awt.Container.addImpl(Container.java:325)
    at java.awt.Container.add(Container.java:252)
    at javax.swing.JMenu.add(JMenu.java:511)
    at wordprocessor.WordProcessorDemo.<init>(WordProcessorDemo.java:68)
    at wordprocessor.WordProcessorDemo.main(WordProcessorDemo.java:18)Any help would be greatly appreciated. Thanks.

    Is that the only thing wrong or is there more to it?

  • Why do I get a black screen when i click on a PDF in a web page?

    why do I get a black screen when i click on a PDF in a web page? Firefox works as is should.

    Hi,
    From your Safari menu bar click Safari / Preferences then select the Extensions tab. If you have any installed, turn that off, then relaunch Safari. Try a PDF file.
    If it's not Extensions, open a Finder window. Select MacintoshHD in the Sidebar on the left. Now open the Library folder then the Internet Plug-Ins folder. If you see any files such as this:
    AdobePDF Browser or Viewer Plug-in
    Move it to the Trash, relaunch Safari.
    Carolyn :-)

  • How to get the Useru2019s position when the user doesnu2019t have CP relation

    We have a custom program which will add / delete attributes (In transaction PPOSA_BBP). It is working fine for users which were assigned with CP relation But it fails for users which doesnu2019t have CP relation (since we are getting the position of users form HRP1001 then we are retrieving the existing attributes based on the position after that updating the attributes) as we are getting the position from HRP1001 it fails for users were no CP relation.
    Help us how to get the Useru2019s position when the user doesnu2019t have CP relation. Suggest us any function module or how to query the HRP1001 or some other table if exists
    Regards
    Paul

    Hi Paul,
    Have a look at these tables.
    Using table BUT000 the central business partner data are stored, f.e. partner type, partner names, partner number, partner guid, person number, etc. In table BUTBKK the bank data to a business partner are stored.
    Central business partner address data
    The table ADRC is used for the address of a business partner. Table BUT020 links the business partner number with the address number. Using table BUT021 several addresses to a business partner with different usages (modes), f.e. correspondence or delivery address, can be stored. The personal data of a business partner person are stored with key person number in table ADRP. The person number is assignd to a business partner person in table BUT000. Communication data of business partners as e-mail, telephone, fax, etc. are stored in the tables ADDR1 u2013 ADDR12. The business address of a contact person or an employee consists of the organization address (company resp. org.-unit) and of an address addition, which describes f.e. a building, a room number, etc. The address addition is stored in table ADCP and is identified by the keys address number of the organization address and person number.
    Relationships between business partners
    Table BUT050 contains the relationships between a business partner organization and a business partner person using relation types. The relation types are defined in table TBZ9, f.e. the relation type u2018has employeeu2019 corresponds to identifier u2018BUR010u2019, the relation type u2018has contact personu2019 corresponds to identifier u2018BUR001u2019. Table BUT051 stores communication data of a contact person relationship (compare to table ADCP). Table BUT052 stores several address numbers to one business partner relationship (including a standard flag).
    Hope this helps,
    Kind Regards,
    Matthew

  • Why am I getting an error message when trying to use a template?

    Why am I getting an error message when trying to use a Pages template?

    You are getting an error message because there is an error.
    Knowing wht version of Pages you are using, what template you are attempting to open, and what error message Pages is sending you might help determine why you are getting that specific rror message. Without those, the first sentence above i pretty much all that can be said with any assurance.
    Regards,
    Barry

  • Why do i get the following message when i attempt to open my backup file for lightroom cc?  "Lightroom cannot use the catalog named "Lightroom Catalog" because it is not writable and cannot be opened".  This message just started coming  up after downloadi

    why do i get the following message when i attempt to open my backup file for lightroom cc?  "Lightroom cannot use the catalog named "Lightroom Catalog" because it is not writable and cannot be opened".  This message just started coming  up after downloading lightroom cc (previously using lightroom 5)...am i backing up properly or not???

    Open Pictures folder and move the files named lrcat-journal and lrcat.lock to Desktop.
    Make sure that , they are not inside Pictures folder any more and try to open backup from Lighrtroom and check..
    Any LRcat file with .lock extension , move it to Desktop.

  • Why do I get "generic error" message when trying to upload a self-created, 1hr .wmv file?

    I went through the forums and made sure that any blocks or copywrites weren't triggered by the file, it's clean and can be opened using a media player and other video editing software like windows MovieMaker. I keep getting "The importer reported a generic error" message and have no idea how to proceed. Can someone please help?

    Re: Why do I get "generic error" message when trying to upload a self-created, 1hr .wmv  file?
    This ARTICLE starts with a checklist on setting up a computer to run PrE best, then goes into a series of links for tuning up one's computer and OS, and then links on troubleshooting.
    There is also a link on posting all necessary info, to help others help you.
    Without knowing much more about your system, it is impossible to say much beyond that WMV's are tough assests to work with, requiring a lot of CPU horsepower.
    Good luck,
    Hunt

  • Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    Why do I get an error message when I try to sync my IPAD with ITunes? Message reads Cannot be used because Apple Mobile Device Service has not been started.

    AMDS for Windows
    http://support.apple.com/kb/TS1567

  • Why am I getting error code 1402 when trying to update adobe reader 10?

    Why am I getting error code 1402 when trying to update adobe reader 10?

    Impossible to guess the "why" with so little information, but this may be helpful if you want to solve the problem: Error 1402 | Error 1406 | Acrobat, Reader

  • Why do I get this error message when I open Organizer in Photoshop Elements 11 "Elements Organizer has stopped working"? My only option is to Close Program so I am effectively locked out of my photo catalogue.  I have reinstalled the program to no avail.

    Why do I get this error message when I open Organizer in Photoshop Elements 11 "Elements Organizer has stopped working"? My only option is to Close Program so I am effectively locked out of my photo catalogue. I have tried reinstalling the program but it made no difference to the error message.
    Could someone help please?  Steph

    Hi,
    Please give a try to Photoshop Elements (PSE) knowledge base. steps mentioned on this and see if it works.
    Regards
    Kishan

  • Why do I get a black version when I convert my document to PDF?

    I have been using Microsoft Publisher 2007 with XP to produce a newsletter for over 11/2 years. Today when I converted the file to PDF it is black with all kinds of wierd colors. It looks nothing like the document I produced. This has never happened before. The PDF version last month looked exactly like the white background document I produced with all the fonts in the right colors, including the pictures. This one looks like a 4 year old got ahold of it and colored it any way she wanted. Nothing looks the same as my document. What happened?

    I found out that if I waited about 15 minutes the PDF file became normal. Thank heavens! I've now sent out my newsletter for my Quilt Club to our 90 e-mail subscribers and all of them I have heard from have gotten it the way I had written it. It must just have been a quirk that happened, but I sure am glad it fixed itself. I only have 5 more newsletters to write and then I am done. Thank Heaven. Thank you for trying to help. I was about to become even more crazed than I get when I have to publish the newsletter. I do it once a month and I never would have volunteered for the 2 year job if I had know how much work it is. My husband walks gently when he knows I am trying to put the newsletter together. I'm not usually crabby, but this has made me a nut case once a month. It's a good thing we've been married for 37 years, so he knows that it is only the "newsletter editor nutty lady" that is getting mad at everything and everyone, including him! Thanks for trying to help. You were the only one that answered. JO
    Date: Tue, 6 Jul 2010 03:29:03 -0600
    From: [email protected]
    To: [email protected]
    Subject: Why do I get a black version when I convert my document to PDF?
    How did you convert the file to PDF?
    >

  • Why do i get a black screen when i open a pdf file?

    why do I get a black screen when I open a pdf file?

    I'm seeing the same thing, as well as "zombie" AcroRd32.exe *32 processes.
    (I'm seeing this on Windows 7, not Windows 8.)

  • Why do I get a black screen when I start my macbook pro?

    why do I get a black screen when I start my MacBook pro?

    Hello szimmerli2 and welcome to Apple Support Communities,
    It will help us diagnose your problem to know the exact model, size, year built, RAM installed and OS you're running.

  • TS3694 Why am I getting error code 3194 when i try to restore my ipod?

    Why am I getting error code 3194 when I try to restore my ipod touch 4th generation

    This device is not eligible for the requested build: Also sometimes displayed as an "error 3194." If you receive this alert, update to the latest version of iTunes. Third-party security software or router security settings can also cause this issue. To resolve this, follow Troubleshooting security software issues.
    Downgrading to a previous version of iOS is not supported. If you have installed software to perform unauthorized modifications to your iOS device, that software may have redirected connections to the update server (gs.apple.com) within the Hosts file. First you must uninstall the unauthorized modification software from the computer, then edit out the "gs.apple.com" redirect from the hosts file, and then restart the computer for the host file changes to take affect.  For steps to edit the Hosts file and allow iTunes to communicate with the update server, see iTunes: Troubleshooting iTunes Store on your computer, iPhone, iPad, or iPod—follow steps under the heading Blocked by configuration (Mac OS X / Windows) > Rebuild network information > The hosts file may also be blocking the iTunes Store. If you do not uninstall the unauthorized modification software prior to editing the hosts file, that software may automatically modify the hosts file again on restart. Also, using an older or modified .ipsw file can cause this issue. Try moving the current .ipsw file, or try restoring in a new user to ensure that iTunes downloads a new .ipsw.
    Error 3194: Resolve error 3194 by updating to the latest version of iTunes. "This device is not eligible for the requested build" in the updater logs confirms this is the root of the issue. For more Error 3194 steps see: This device is not eligible for the requested build above.
    http://support.apple.com/kb/TS3694#error3194
    Also see:
    iPhone Error 3194 - How to Fix iTunes Error 3194?

Maybe you are looking for

  • GR/IR account functionality

    Dear Guru's, Any one please calarify, how gr/ir account functions iam not clear about this one, what i understand is 1)GR/IR account is a gl account with open item managed one. 2) when goods received it was posted by crediting to this account and deb

  • Airport Express 6.3

    I am running Maverics on my Mini, is there a way to install mountain lion OS X on an external hard drive connected to my Mini? I need to do this so I can admin my airport express 6.3

  • How do I edit a PDF? Once it is saved I can no longer edit the doc....

    I saved a PDF from an online site and now that I need to edit some info, I don't know how to do it... Help, please!

  • REM Scenario

    Dear All, I'm into REM Manufacturing Scenario... I want to do GI after posting GR through MFBF Transaction against Planned Order. Once the Planned Order Quantity is completed I cannot do GI as the Planned Order is already reduced. I have also tried t

  • Implementing SRM-MDM with WebDynpro ABAP or JAVA and OCI

    Hi, I have the following situation at one of our clients. They have implemented the SRM-MDM catalog. Via MDM the SRM server displays the catalog via ITS. Now I want to make a WebDynpro which can talk to SRM-MDM catalog and sends the data to the shopp