Results 1 to 4 of 4
  1. #1
    Swingset is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default Selecting a JMenu paints over the JPanel on the content pane

    Hi.

    As the title says, every time I select a JMenu from the menu bar and menu items drop down, the space taken over by the menu items gets painted over.

    An example of it happening can be seen here:



    where the gray area is where the Input menu has dropped down.

    Does anybody know how to stop this from happening?

    Thanks.

    :).

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Possible areas of trouble may include:
    1 Mixing AWT and Swing (J-prefix) components
    2 improper implementation of paint/paintComponent method overrides.
    Need more information to go farther.

  3. #3
    Swingset is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default

    Hi.

    Cheers for replying.

    I'll try and go into a bit more detail.

    I've got a class which extends a JPanel.

    I've got some boolean variables which can be set by calling methods (e.g. blankScreen). The JPanel's repaint() method is then called.

    I've overriden the paintComponent() method to call certain methods dependent on the value of the booleans.

    The appropriate method is called using the paingComponent's Graphics object as a parameter.

    When the JPanel is painted for the first time when the GUI is created, the painting over effect does not occur. It only seems to happen once it has been repainted.

    Thanks for any help people can give.

    :)

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Make sure you call super to avoid artifacts:
    Java Code:
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // carry on with custom drawing...

Similar Threads

  1. JFileChooser example (selecting a directory)
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 02-03-2009, 01:25 PM
  2. Selecting parts of an image
    By shaungoater in forum Java 2D
    Replies: 1
    Last Post: 12-15-2007, 10:06 PM
  3. JMenu calling another Forms/Panels
    By plodos in forum New To Java
    Replies: 2
    Last Post: 12-10-2007, 08:02 AM
  4. selecting a record in database
    By ramachandran in forum New To Java
    Replies: 0
    Last Post: 10-25-2007, 07:06 AM
  5. JMenu and JRadioButtonMenuItem
    By doron70 in forum AWT / Swing
    Replies: 3
    Last Post: 07-18-2007, 06:13 PM

Posting Permissions

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