Painting issues in Swing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seanus
    New Member
    • Feb 2007
    • 6

    Painting issues in Swing

    Hey all, I've recently started coding a program for my final year project of my uni degree. I am coding in Swing and have a very odd bug.

    I'm using TabbedPane for the first time, although I've used CardLayout before and there seems little difference between them. I am generating my own version of a JPanel and inserting them into the JPanel on one of the tabs of the TabbedPane, this all works fine(ish - wont go into that one now).

    The bug I'm getting came along when I applied a mouseListener to the personalised JPanels, so that I can change the colour of a drawn border (using only drawline commands) upon mouse click. I've used the border and colour code on a previous project with no problems. Now when I click on a panel to effectively highlight it the contents of the panel (previously a bunch of JTextPanels in a GridBagLayout) get replaced with what seems like a part screen dump of my program, the part screen dump cannot be interacted with even when it replicates buttons etc. Here's the kicker, the screen dump thing also contains random fragments of what the panel used to contain, none of which will be aligned within the panel as it should've been.

    This explaination may seem vague but it feels like a problem that would have been seen before. I will happily paste up the code if need be, it just seems like it may be down to my lack of experience with Swing.

    I'm also more than happy to provide print screens if that will help.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Seanus
    Hey all, I've recently started coding a program for my final year project of my uni degree. I am coding in Swing and have a very odd bug.

    I'm using TabbedPane for the first time, although I've used CardLayout before and there seems little difference between them. I am generating my own version of a JPanel and inserting them into the JPanel on one of the tabs of the TabbedPane, this all works fine(ish - wont go into that one now).

    The bug I'm getting came along when I applied a mouseListener to the personalised JPanels, so that I can change the colour of a drawn border (using only drawline commands) upon mouse click. I've used the border and colour code on a previous project with no problems. Now when I click on a panel to effectively highlight it the contents of the panel (previously a bunch of JTextPanels in a GridBagLayout) get replaced with what seems like a part screen dump of my program, the part screen dump cannot be interacted with even when it replicates buttons etc. Here's the kicker, the screen dump thing also contains random fragments of what the panel used to contain, none of which will be aligned within the panel as it should've been.

    This explaination may seem vague but it feels like a problem that would have been seen before. I will happily paste up the code if need be, it just seems like it may be down to my lack of experience with Swing.

    I'm also more than happy to provide print screens if that will help.
    Yep, you have to post the code.

    Comment

    • sreenulanka
      New Member
      • Jan 2007
      • 6

      #3
      Originally posted by r035198x
      Yep, you have to post the code.
      call repaint method when ever components are add or delete.finally call paint method.within paint method call super(); class method.
      public void paint(Graphics g)
      {
      super(g);
      }

      Comment

      • Seanus
        New Member
        • Feb 2007
        • 6

        #4
        Originally posted by sreenulanka
        call repaint method when ever components are add or delete.finally call paint method.within paint method call super(); class method.
        public void paint(Graphics g)
        {
        super(g);
        }
        Ok thanks, I will go over my code to ensure this. I'm having another day of it today and will post my code this evening. Thanks for the interest so far guys.

        Comment

        • Seanus
          New Member
          • Feb 2007
          • 6

          #5
          sreenulanka - I owe you one / would like to request your children. It was the super call after all, but it wasnt in the program's paint method that made the difference, it was calling the super paint method from my personalised JPanels.

          Thanks very much, you just saved me muchos time. Dont u hate how the most complex looking bugs are always one liners!

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Seanus
            sreenulanka - I owe you one / would like to request your children. It was the super call after all, but it wasnt in the program's paint method that made the difference, it was calling the super paint method from my personalised JPanels.

            Thanks very much, you just saved me muchos time. Dont u hate how the most complex looking bugs are always one liners!
            Saved us all a lot of time going over your code.

            Did you say you are requesting lanka's children?

            Comment

            • Seanus
              New Member
              • Feb 2007
              • 6

              #7
              Yeah....see, that was a spur of the moment happy feelings kind of children request, just to make things absolutely clear, I will not or have not ever come close to even entertaining the idea of contemplating exploring the concept of thinking about kidnapping your children : )

              But yeah, thanks again for the code help

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                Originally posted by Seanus
                Yeah....see, that was a spur of the moment happy feelings kind of children request, just to make things absolutely clear, I will not or have not ever come close to even entertaining the idea of contemplating exploring the concept of thinking about kidnapping your children : )

                But yeah, thanks again for the code help
                Well that's a relief.

                Comment

                Working...