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 4 of 4

Thread: Replacing a JButton

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Replacing a JButton

    Hi,

    I'm not sure how I can go about replacing a JButton with a JRadioButton when the JButton is clicked. So say if I had Jpanel set as a gridlayout which lays out 4 rows (3 JLabels and a JButton). So when the user clicks the JButton, that JButton will be replaced with a JRadioButton.

    Would I use a CardLayout for this purpose, or is there a simple way in replacing that JButton?

    Thanks, much appreciated


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,935
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Replacing a JButton

    An idea: put the component in a JPanel and add that JPanel to the grid layout. Then try removing the component from the panel and adding a different component.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    57
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Replacing a JButton

    Yes I could add the new RadioButton at position 3 (4th row JButton) to the JPanel, and removing the initial JButton. Thanks for the reply

  4. #4
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Replacing a JButton

    Another option is to add both components to the JPanel but have one not visible. You can then make them appear and disappear at will without much effort.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

Similar Threads

  1. [SOLVED] replacing few keywords with corresponding operators
    By shenaz in forum Java Theory & Questions
    Replies: 14
    Last Post: April 9th, 2013, 12:54 PM
  2. Replacing a JButton with an Image
    By tyeeeee1 in forum Java Theory & Questions
    Replies: 5
    Last Post: December 4th, 2012, 02:21 PM
  3. replacing thread with timer
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: December 3rd, 2012, 08:49 AM
  4. [SOLVED] Replacing dots with spaces
    By dTi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 17th, 2011, 08:53 PM
  5. [SOLVED] replacing subString
    By nasi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 21st, 2010, 10:47 PM

Tags for this Thread