Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JPanel in a Vector: pb

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JPanel in a Vector: pb

    Dear all,

    I get an error when trying to get a JPanel from a Vector:

    JComponentsResults result; // (JComponentsResults extends Vector)
    ...
    System.out.println("String Representation of the Vector:" + result.toString());//debugging
    (JPanel) toto = (JPanel)result.get(iComponent);

    The output is :
    ************
    Exception in thread "AWT-EventQueue-0" String representation : [[javax.swing.JPanel[,0,0,0x0,layout=java.awt.GridBagLayout,alignmentX= 0.0,alignmentY=0.0,border=,flags=9,maximumSize=,mi nimumSize=,preferredSize=]]]
    java.lang.ClassCastException: java.util.Vector cannot be cast to javax.swing.JPanel
    at Session.displayResults(Session.java:158)
    ************

    I Tried to cast to JComponent, it does not work either.
    Is it possible to get JComponents from a Vector ?

    Any idea will be appreciated.
    Thanks.
    Eric

    ~


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: JPanel in a Vector: pb

    A small simple that illustrates the problem would be helpful. It should be compilable and run but doesn't need all your program logic: it is enough to should show the declaration of result, and the code used to put things into it.

Similar Threads

  1. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  2. [SOLVED] Pesky <JPanel>.getWidth() and <JPanel>.getHeight() Methods...
    By snowguy13 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 31st, 2011, 03:35 PM
  3. Replies: 2
    Last Post: December 22nd, 2010, 09:21 AM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM