Results 1 to 6 of 6
  1. #1
    ash03e608 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Thumbs up Component loses GraphicsConfiguration when added to Container

    I noticed that when a component (ex Canvas, JFrame) is constructed with a specific GraphicsConfiguraton(GC) and then when added to a Container (ex JPanel) , the GC of the container overwrites the GC of the component.

    This seems to be a new change with Java 7, in Container.addImpl method.

    I am trying to render a Canvas in stereo mode on Linux. I make sure i choose a GraphicsConfiguration which is stereo capable for the construction of my canvas. When i add this canvas to a JPanel or any other container, the GC of the JPanel (which is probably the default GC of the device) overwrites my canvas' Gc. This makes stereo impossible for my application right now.

    I tried using reflection and custom calls to addNotify and removeNotify to reset the GC on the canvas and recreate the peer. However this dirty fix does not work for other parts of my application like FullScreen, undocking/docking etc.

    Any suggestions for my problem ?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,534
    Rep Power
    5

    Default Re: Component loses GraphicsConfiguration when added to Container

    Perhaps you should demonstrate your problem with a simple Short, Self Contained, Correct Example.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    ash03e608 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default Re: Component loses GraphicsConfiguration when added to Container

    import java.awt.Canvas;
    import java.awt.GraphicsConfiguration;
    import java.awt.GraphicsEnvironment;

    import javax.swing.JPanel;

    public class TestGC {

    /**
    * @param args
    */
    public static void main(String[] args) {
    JPanel panel = new JPanel();
    //Assume this GC is a special stereo capable Graphics Configuration
    GraphicsConfiguration gc= GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getConfigurations()[0];
    Canvas c = new Canvas(gc);
    System.out.println(c.getGraphicsConfiguration());
    panel.add(c);
    System.out.println(c.getGraphicsConfiguration());


    }

    }

    Expected Result:
    X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]
    X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]

    Actual Result:
    X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]
    null


    Quote Originally Posted by jim829 View Post
    Perhaps you should demonstrate your problem with a simple Short, Self Contained, Correct Example.


    Regards,
    Jim

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,534
    Rep Power
    5

    Default Re: Component loses GraphicsConfiguration when added to Container

    Well, I looked at the code. It appears to ignore it. Or at best, ensure it is the same as the parent container. Why do you want to specify it anyway?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    ash03e608 is offline Member
    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Default Re: Component loses GraphicsConfiguration when added to Container

    Like I mentioned in my first post :
    I am trying to render a Canvas in stereo mode on Linux. I make sure i choose a GraphicsConfiguration which is stereo capable during the construction of my canvas. When i add this canvas to a JPanel or any other container, the GC of the JPanel (which is probably the default GC of the device) overwrites my canvas' Gc. This makes stereo impossible for my application right now.

    If any GC taken in the Canvas's constructor is going to be overridden. Then what is the point of this constructor at all ?


    Quote Originally Posted by jim829 View Post
    Well, I looked at the code. It appears to ignore it. Or at best, ensure it is the same as the parent container. Why do you want to specify it anyway?

    Regards,
    Jim

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,534
    Rep Power
    5

    Default Re: Component loses GraphicsConfiguration when added to Container

    I tried something and it appeared to work. I am assuming you cannot mix graphics contexts. So I did the following.

    Java Code:
    public class TestGC extends Panel {
       Frame frame;
       public TestGC() {
          
          GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations()[0];
          frame = new Frame(gc);
          System.out.println(gc);
          Canvas c = new Canvas(gc);
          frame.add(this);
          System.out.println(c.getGraphicsConfiguration());
          add(c);
          System.out.println(c.getGraphicsConfiguration());
          
       }
       public static void main(String[] args) {
          new TestGC();
       }
    I believe you have to establish the graphics contexts from the top down so that they don't get reset to default. I started off Java using AWT and then migrated to Swing. However, I am not certain it is wise to mix the two. So unless someone else on this forum corrects me, I would suggest you stick with AWT if using Canvas.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 0
    Last Post: 01-17-2012, 04:53 PM
  2. drawing only the most recently added component?
    By billycro in forum New To Java
    Replies: 10
    Last Post: 07-03-2011, 08:55 PM
  3. Bring component to front of a container?
    By Cruncher in forum New To Java
    Replies: 9
    Last Post: 04-26-2010, 11:32 PM
  4. Replies: 1
    Last Post: 04-01-2009, 02:00 AM
  5. how to remove all component in container(Jpanel)
    By SaYuNaRa in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 04:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •