Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

text alignment for Jtextfield

 
satya saha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

How to align text in jtextfield to top.

My problem is here I am taking rgb values from jtextfield but because of text alignment in middle there is lot of white spaces in my rgba array in top and bottom .
can You please suggest how to get text exactly without getting white space top and bottom,

i need where i need to start in order to get correct text.

code:

Insets in=new Insets(0,0,0,0);
jTextField1.setMargin(in);
Dimension bounds = jTextField1.getPreferredSize();
final BufferedImage image = new BufferedImage(bounds.width, bounds.height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();
SwingUtilities.paintComponent(g2d, jTextField1, new Container(),
0, 0, bounds.width, bounds.height);
jTextField1.paint(g2d);
g2d.dispose();
image.getRgb(0,0,bounds.width,bounds.height,null,bounds.width);

also i tried with this code

image.getRgb(0,40,bounds.width,bounds.height,null,bounds.width); it is giving me error

please help me

Thanks in Advance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'quest for knowledge' as a nic would indicate your willingness to comply with rules and requests.

the simple solution may be supplied when you comply.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:'quest for knowledge' as a nic would indicate your willingness to comply with rules and requests.

the simple solution may be supplied when you comply.
Thank you for noticing, Michael.

Member 178781, back to your private messages please.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic