Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
How do I Center Align text using drawString?
Matt Wilcko
Ranch Hand
Posts: 65
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have the line:
g2D.drawString("test sentence",350,200);
Any way to get the text center aligned?
Thanks!
kyle amburn
Ranch Hand
Posts: 64
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The following code segment will center a
String
by passing the startin x,y and the available width.
private void printSimpleString(String s, int width, int XPos, int YPos){ int stringLen = (int) g2d.getFontMetrics().getStringBounds(s, g2d).getWidth(); int start = width/2 - stringLen/2; g2d.drawString(s, start + XPos, YPos); }
Kyle
dhaya ananth
Greenhorn
Posts: 2
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
please help me the same above needs to align right...
thanks in advance
Darryl Burke
Bartender
Posts: 5167
11
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It's very similar, so why don't you give it a try and post your best efforts, in the form of an
SSCCE
<= link
If you're still not getting the desired results, we can then guide you to a successful conclusion.
luck, db
There are no new questions, but there may be new answers.
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Centering the header of the columns in JTable
Center text of title bar
Issue with centering Label text
regarding JTableHeader
Centering Text in TEXTAREA
More...