473,467 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Java wrap text to polygon

28 New Member
I am using Java Graphics2D to draw basic and complex polygons which will have text of varying lengths and fonts in it. What I'm trying to achieve is that the text drawn is perfectly wrapped and clipped to fit within the polygon.

The code I have so far is this:

Expand|Select|Wrap|Line Numbers
  1. int[] xp = { x + width /2, x + width -1, x };
  2. int[] yp = { y, y + height - 1, y + height - 1 };
  3. g.setColor(fill.color1);
  4. g.fillPolygon(xp, yp, xp.length);
  5. g.setColor(border.color);
  6. g.setStroke(new BasicStroke((float) (border.width * zoom), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
  7. g.drawPolygon(xp, yp, xp.length);
  8.  
  9. // Later on in the method..
  10. g.drawString(text, textx, texty);
  11.  
This draws the shape and text fine but the text is just one long line. I want it to fit neatly into the polygon.

Thanks,
Josh.
Sep 16 '13 #1
0 1510

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mark P | last post by:
My images are fixed in size and can't be redone. Many of them are tall and narrow. How can I wrap text so that the text starts on the right of the image at a level with the top of the image....
2
by: amber | last post by:
Hello, I have a datagrid column header that is quite long, and I would like it to appear on 2 lines instead of 1. Is this possible? TIA. Amber
1
by: Grant Hammond | last post by:
I assume I'm not alone in my frustration that the expression builder that comes (in part) with Access XP that dosnt wrap text when you open it on an exisitng expression in a query or form. I's...
0
by: Norman Fritag | last post by:
Hi there, 1) I is there a more elegant way, more professionally way this export could done, as I have written some code for the first time? 2) who could I wrap text cell a1 a3 via code ? 3) is...
4
by: searider86 | last post by:
Does anyone know if there is a snippet of code that automatically removes the wrap text format in excel? I have an access form that displays data and allows the user to click on a cmdbutton to...
1
by: Diego | last post by:
Hi, how do I set the wrap property to FALSE for a datagrid with autocolums enabled? I know there's a work around this bug when the columns are set up in design time but I need the autocolumns...
2
by: Rocco | last post by:
Hi, I have a drop down box with width=120px. The box length cannot be extended because of design issue. How can I wrap text in html drop down box ? Thanks, Rocco
0
by: Keithb | last post by:
I have a GridView control with 2 template columns. Both contail a Label control in their ItemTemplate. The right column label wraps text on long strings, the left column just gets wider with long...
15
by: removeps-groups | last post by:
How to wrap text in <ptag if the text has no spaces and is very long? Here is an example: ...
3
by: raamay | last post by:
I picked up the below code from some website and it is absolutely good working code except that the wrap text feature is not available. The value of field1 below do not go to a new line if the value...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.