• Post Reply Bookmark Topic Watch Topic
  • New Topic

actionlistener and restricting size of button  RSS feed

 
Manjunath A.S
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have few queries using swing?

1. can somebody tell me how do i restrict the size of the button that we create using swing?
2. how to place a particular button at a desired location?
3. how to check whether the user has typed 10 characters or 20 and so on?
4. how to create password window such that it shouldnt display anything when the user types password . also, how to use action listener when user completes typing password and presses enter?
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

The restriction on the JButton has to do with the Layoutmanager you are using.
You can use the inherited method from JComponent setPerferredSize() to set the size.

If you meen by password that the user only will see ***** when he/she types you can use the JPasswordField. Package javax.swing

to check the length you can do it by checking the .length() on the text. If you want to alert the user then add a keypressListener and check the length in there. See java.awt.event

To add a ActionListener to a button you can try the following

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!