Stop Painting over JComboBoxes?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Stop Painting over JComboBoxes?

  1. #1
    Join Date
    Feb 2005
    Posts
    4

    Stop Painting over JComboBoxes?

    I'm programming a game in Java (MasterMind) that uses simple graphics, and JComboBox to get inputs. The problem is that the graphics "paint over" the options in my JComboBoxes. When I mouse hover over the options, the problem fixes itself, but the initial graphics getting in the way is annoying. My code is kind of a mess so far, so it would probably be better to just post a screenshot, since I haven't made any sense so far:



    As you can see, the colored pegs get in the way of my selections. Any way around this? Any help would be greatly appreciated... my project is due Tuesday! Thanks in advance!

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Check below....
    eschew obfuscation

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The boutique server has really gotten its nickers in a
    twist his morning. - My first reply got 'lost' at first,
    so I rewrote it and here I am with two.

    anyway:
    I suspect that you are adding standard components/
    layoutmanagers to the container that you have
    overridden the paint/update methods for ( ? )
    If that is the case I can only wish you good luck;
    I have naver been able to find a failsafe method for
    making that mixture work. The only component I have
    been able to use like that is the popUpMenu, and that
    might be an option for you.

    If not, then you should zip your source code (however
    messy) and post it here so we can have a look at it.

    eschew obfuscation

  4. #4
    Join Date
    Feb 2005
    Posts
    4

    The Code

    Here's my Code... (6 classes, MasterMind.java is where all the magic happens though).

    http://home.comcast.net/~falcorthedog/Code.zip

    Please help! Thanks!

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I was right in my guess; in your MasterMind JFrame
    you add your comboboxes to the container that you
    have overridden the paint method for. The game
    works 'fine' when I pull the frame in the right side,
    increasing the width so the comboboxes land outside
    the gameBoard....

    Judging from your code you shouldn't have any problems
    replacing the comboBox strategy with a popupMenu
    that, on a rightButtonClick, appearred in one of four
    squares laid out horisonatlly over one line of peg-holes.

    Or the more longwinded solution where you build the
    whole gameBoard up with panels. Then you can at
    least keep the comboBoxes.
    eschew obfuscation

  6. #6
    Join Date
    Feb 2005
    Posts
    4

    Panels

    ...but the ComboBoxes are in a JPanel. What do you mean exactly? (regarding the "long winded" solution)

  7. #7
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    As far as I can see that JPanel is added to the container
    thet you have overridden the paint() method for.

    The long winded solution is converting the game board,
    that currently is being drawn 'manually' to a setup (e.g.
    with a boxLayout) where all the squares on the game-
    board are JPanels. The panel that will contain the
    comboboxes will then be shifted upwards during the
    guess-progression. Also; the colorCircles could be
    replaced by iconImages.

    I am pretty sure that this setup will work, and I even
    beleive it will reduce & simplyfy the code.
    eschew obfuscation

  8. #8
    Join Date
    Feb 2005
    Posts
    4

    Thanks

    Thanks for the info sjalle. The project is due Tuesday, so I think I'm just going to live with my comboBoxes, but I appreciate your advice. If I get more time, I might try that setup. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center