• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

including an icon inside a text field.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree we are splitting hair here, but then we end up with three components instead of one.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic