• Post Reply Bookmark Topic Watch Topic
  • New Topic

including an icon inside a text field.  RSS feed

 
Arun Thulaseedharan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i want to include an icon inside a JTextField(at the extreme right)and when that icon is clicked a dialog box should appear.Can anyone suggest an approach for doing this??
thanks in advance.
arun
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arun Thulaseedharan:
hi all,
i want to include an icon inside a JTextField(at the extreme right)and when that icon is clicked a dialog box should appear.Can anyone suggest an approach for doing this??
thanks in advance.
arun


1) Override the JTextField#paintComponent to paint the Icon at your desired location.
2) Add a MouseListener to your JTextField.
3) On receiving mouse clicks, find out if the click happened on your icon.
4) If yes, process it accordingly.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a component:
JPanel(BoxLayout) with JTextField and JLabel(icon).
modify borders so it looks like a single component.
add mouseListener to the label (to do whatever you want).
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree we are splitting hair here, but then we end up with three components instead of one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!