Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Problem with borders appearing

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with borders appearing

    I have 2 ButtonGroups which I want to have separate titled borders for. This is the code I'm using to set it up but it doesn't work. Can someone have a suggestion? I'm just a beginner.

    JPanel sizePanel = new JPanel();

    ButtonGroup style = new ButtonGroup();

    sizePanel.setBorder(BorderFactory.createTitledBord er("Varietal"));


    chardonnay = new JRadioButton("Chalone");
    cabernet = new JRadioButton("Silver Oak");
    zinfandel = new JRadioButton("Oppolo");
    style.add(chardonnay);
    style.add(cabernet);
    style.add(zinfandel);

    panel1.add(chardonnay);
    panel1.add(cabernet);
    panel1.add(zinfandel);

    ButtonGroup bottle = new ButtonGroup();

    sizePanel.setBorder(BorderFactory.createTitledBord er("Bottle Size"));


    split = new JRadioButton("Split");
    fifth = new JRadioButton("Fifth");
    magnum = new JRadioButton("Magnum");
    bottle.add(split);
    bottle.add(fifth);
    bottle.add(magnum);


    panel1.add(split);
    panel1.add(fifth);
    panel1.add(magnum);


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,483
    My Mood
    Hungover
    Thanks
    144
    Thanked 643 Times in 548 Posts

    Default Re: Problem with borders appearing

    When posting code, please use the highlight tags, and post your code as an SSCCE, not as a snippet or your whole program.

    What JPanels are you adding each set of buttons to (the ButtonGroups are irrelevant)? What JPanels are you adding borders to?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with borders appearing

    Should they be going to the same object?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,483
    My Mood
    Hungover
    Thanks
    144
    Thanked 643 Times in 548 Posts

    Default Re: Problem with borders appearing

    ButtonGroups do not have an encompassing gui. For example, you can't put a border on a ButtonGroup. You can even have JButtons from one ButtonGroup on multiple JFrames.

    However, you can add all of the JButtons from one ButtonGroup to a JPanel, and all of the JButtons from another ButtonGroup to a different JPanel, then give each JPanel its own border.

    It's unclear what you're trying to do in your code, so if you want more specific help, I suggest posting the SSCCE.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with borders appearing

    I am creating a border with a title and adding 3 buttons to it. I then create a second border with a different title and add 3 different buttons to it. I want the panel to show 2 borders with 3 buttons in each. What's happening is it is displaying the second border with 6 buttons in it.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Problem with borders appearing

    Quote Originally Posted by michael.duffy31 View Post
    What's happening is it is displaying the second border with 6 buttons in it.
    In the posted code I see 6 places where you added to panel1.... perhaps in some code not posted you had a panel2 you meant to add things to?

Similar Threads

  1. menu bar is not appearing
    By saurabh_kabra in forum AWT / Java Swing
    Replies: 8
    Last Post: March 29th, 2013, 01:52 PM
  2. menu bar is not appearing
    By saurabh_kabra in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 29th, 2013, 01:44 PM
  3. Components not appearing (need help!)
    By hawkeye01 in forum Object Oriented Programming
    Replies: 6
    Last Post: March 24th, 2013, 09:41 AM
  4. Problem with Bearing calculation appearing as NaN
    By welshcrossy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 23rd, 2012, 10:23 AM
  5. [SOLVED] Shapes: How to Outline with Thick Borders?
    By snowguy13 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 4th, 2012, 04:16 PM