Results 1 to 2 of 2
  1. #1
    Acteon is offline Member
    Join Date
    May 2011
    Rep Power

    Default Prevent re-arrangement of component's position if some are invisible.


    When making a dice game, I used a JPanel on which I placed 7 disabled radio buttons. Like this:


    (I'm not sure how to display it with a courrier new font in this message).

    My plan was for example if I roll a 1, I hide all radio buttons except the center one. If I roll a 2, I make visible the NW and SE button. If I roll a 6, I hide the center button and make the other buttons visible.

    The problem I am having is that when I make my radio buttons invisible, the position of my radio buttons get re-arranged on my JPanel so that for example if I roll a 1, the middle Radio button finds itself completly in the top middle part of my panel. If I roll a 3 I don't get a nice diagonal line, the center button gets moved out of alignment.

    How do I fix the position of my Radio buttons on the panel so that they never move regardless of if they are visible or not ?

    I suppose I could use graphics function to draw the dice, but it seems to me that using radio buttons would be simpler.
    Last edited by Acteon; 05-05-2011 at 02:42 PM. Reason: Trying to align the buttons

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    Or paste your code between a pair of {code} tags.

    I would use JLabels in a GridLayout(3, 3) and set the text to "o" or ""


    edit: Better than "o" could be "●" (\u25CF)
    Last edited by DarrylBurke; 05-05-2011 at 03:51 PM.

Similar Threads

  1. components arrangement
    By sudhakar reddy in forum Java Applets
    Replies: 2
    Last Post: 06-03-2010, 03:58 PM
  2. Set default component's font
    By banhbaochay in forum NetBeans
    Replies: 8
    Last Post: 04-12-2010, 04:15 AM
  3. get position in string from caret position
    By helloworld111 in forum AWT / Swing
    Replies: 5
    Last Post: 02-19-2009, 02:36 AM
  4. arrangement of components
    By masa in forum AWT / Swing
    Replies: 7
    Last Post: 12-12-2008, 11:17 AM
  5. <tr><td> arrangement in a method
    By am17mu in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-16-2008, 05:44 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