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

Thread: about GUI stuff

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default about GUI stuff

    My question is why doesn't my program work, and by that I mean : (when I click that check box it makes text bold), when I do this in my Study constructor : JCheckBox cb = new JCheckBox("bold"), but when I do it like the example below it works. Please answer, I'm dying to know.Thanks


    public class Study extends JFrame {

    private JCheckBox cb;
    private JTextField tf;

    public Study () {

    cb = new JCheckBox("bold");
    tf = new JTextField(25);


    and later on some more code..



    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: about GUI stuff

    I don't see any code where you make your text bold on clicking the JCheckBox, and I don't see enough information to be able to hazard a guess why your code isn't working. Have you gone through the check box tutorial yet? If so, can you show us your ItemListener code?

    Then if still stuck, consider creating and posting an SSCCE that demonstrates your problem.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: about GUI stuff

    rest of code is working, just like my program. but it didn't work when I did this in my constructor : JCheckBox cb = new JCheckBox("bold");
    but when I removed that JCheckBox at the begining, so : cb = new JCheckBox("bold") it worked. can you tell me why ?

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: about GUI stuff

    I cannot guess what may be wrong based on what you've posted so far. You probably have to tell us more and show us more, but before posting more code, please read the forum FAQ to see how to use code tags so that we'll be able to read and understand your code. Good luck.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: about GUI stuff

    you must import (javax.swing.JFrame) first

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: about GUI stuff

    Quote Originally Posted by Mohamad.H View Post
    you must import (javax.swing.JFrame) first
    A guess that the problem is actually compile time, and a guess that they actually posted all of their code (which they did not - did you read post #3 which suggests it is not compile time?). Another reason the original poster should provide an SSCCE as already alluded to, and describe exactly 'what's wrong' in the first place.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: about GUI stuff

    no i didnt read post #3....you are right

Similar Threads

  1. please help with if-else statement, loops and beginner stuff
    By javabeg123 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 6th, 2011, 08:38 PM
  2. serialVersionUID and abstract stuff
    By Blehs in forum Java Theory & Questions
    Replies: 1
    Last Post: August 14th, 2011, 07:21 AM
  3. strong stuff
    By DarkRoast in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 10:02 PM
  4. Can't get it to save stuff with JFileChooser
    By javapenguin in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 11th, 2010, 04:13 AM
  5. VB can do stuff Java can`t ??
    By JFujy in forum Java Theory & Questions
    Replies: 2
    Last Post: September 22nd, 2009, 10:25 AM