Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add in a JCheckBox ?  RSS feed

 
Matthew Muscat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I've almost finished building an Editor in Java, but i'm a bit stuck on creating a JCheckBox that saves your credentials (as in password only) . I would like it to be on a JPanel under the password input box and above the Login and Register buttons.
Could you please help me with these problems. Thanks!
Code:
Login.java (Main class for this problem)
http://pastebin.com/r5U6Ef8Y

PS: The main thing here is using GridLayout, which is what im currently working with but can't seem to get it under the password input box.. check:
http://prntscr.com/5iyovv
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I see you are using 2 GridLayouts. I think you can just put the checkbox stuff in the login panel.


Another approach (probably more simpler) is to add the checkbox panel to the login panel. You currently adding the checkbox panel to the big panel.




Since your checkboxP panel and loginP panel have declared different, the look may be a bit off at first.
 
Matthew Muscat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done what you said, this is what i've currently got and look how it turned out:
http://prntscr.com/5j7mkl

Do i need a GridLayout in that new JPanel (checkboxP)?
The Layout isnt working ..

http://pastebin.com/N5GRrypK
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah you seem to have the layout messed up.

Looking more closely, you have 3 sets of things: 1) the user/password label and text fields, 2) the checkbox and 3) the buttons

Each set of things can be put into its own panel then the big panel add these 3 small panels.

 
Matthew Muscat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've copy and pasted what you've done, although i seem to get errors later on as you removed the CardLayout part of the code. How can I fix this? Even if I delete those parts, the whole program does not work when I click on Login/Register buttons.. Check out this:
http://prntscr.com/5j8bt9

-

http://pastebin.com/YdkXMg49

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add back the cardlayout variable and initialize it accordingly.

It's just the login screen doesn't need to use the card layout.
 
Matthew Muscat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah well could you show me how to do that? Like edit my code. The thing is my other classes use the variable as well.
My editor.java class does:
http://prntscr.com/5j8fdy

I'm a beginner programmer and I've had a fair bit of help in this project, that's why most of the stuff your telling me to do i'm not fully understanding, sorry.
http://pastebin.com/tYt9tzwa
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you using the CardLayout to prompt users to login before they can save/edit/whatever with your editor, correct?

 
Matthew Muscat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said, I didn't do most of the theory, but i assume the CardLayout is used for the ActionListener, when the user clicks on "Login" for e.g, the CardLayout basically chooses which Layout should be shown. That's what I assume, although most of this was copied from a Udemy.com video and i'm still having trouble understanding everything..
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a problem, you shouldn't use stuff that you don't understand in the first place. Trying to get something to work without knowing what you really want to do with it is very dangerous and frustrating to some degree (as time goes by).

I suggest you step back and list out what screens you need/ want, how the screens go from one place to another, etc before you start coding.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!