G.drawString and increase character offset?
Can I modify the character offset value being used in g2d.drawString method?
I want to have more space between characters in a string.
I've tried Google and JavaDoc to find a solution, but failed.
import java.awt.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class WidthExample extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
String text = "The quick, brown fox jumped over the lazy dog.";
render(g2, text, 10, 30, TextAttribute.WIDTH_CONDENSED);
render(g2, text, 10, 60, TextAttribute.WIDTH_SEMI_CONDENSED);
render(g2, text, 10, 90, TextAttribute.WIDTH_REGULAR);
render(g2, text, 10, 120, TextAttribute.WIDTH_SEMI_EXTENDED);
render(g2, text, 10, 150, TextAttribute.WIDTH_EXTENDED);
void render(Graphics2D g, String text, int x, int y, Object widthValue) {
AttributedString as = new AttributedString(text);
as.addAttribute(TextAttribute.FAMILY, "Lucida Bright");
as.addAttribute(TextAttribute.SIZE, new Float(20));
as.addAttribute(TextAttribute.WIDTH, widthValue);
TextLayout tl = new TextLayout(as.getIterator(), g.getFontRenderContext());
tl.draw(g, x, y);
public static void main(String[] args) {
JComponent comp = new WidthExample();
JFrame f = new JFrame("WidthExample");
f.getContentPane().add(comp);
f.setSize(720,300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
Similar Messages
-
Hi Experts,
I want to increase the character length of column in MS SQL Server 2005. How to modify the length of character.Hi Shailesh......
You can modify the character length of UDF from Tools> Customization Tools> User Defined Management
Select the UDF and press Update button and increase character length. Here also you can increase length and can not decrease it......
Regards,
Rahul -
Applescript problems with character offsets and embedded objects in Pages
https://discussions.apple.com/thread/2550810?start=0&tstart=0
The above discussion is archived, but I've noticed a problem witht he solution it proposes.
Essentially, the problem seems to be that the character offset of a selection becomes either inaccessible or out of sync when embedded objects are present in the file.
The following document can be used to demonstrate:
http://images.apple.com/support/pages/docs/ePub_Best_Practices_EN.zip
I've slightly modified the script fromt he previous thread, so here's my own script:
tell front document of application "Pages"
set C to character offset of (get selection)
set N to 0
repeat with P in (get character offset of paragraphs)
if P > C then exit repeat
set N to N + 1
select paragraph (N + 1)
end repeat
N
end tell
This script is supposed to select the next paragraph in a document, when given a selection. The intention is to call it recursively to get each paragraph of the document in turn.
At the start of the document, it functions correctly, however when it gets to the embedded pictures, lines and table of contents, things start to break. This wouldn't be so bad, because I could simply ignore paragraphs that contains those embedded objects, but the real problems arise in the normal text below these objects.
If you place the cursor on the 3rd page of that document, in an ordinary paragraph, for example, this script will simply return the same paragraph over and over. The reason for this is that the character offset of the paragraphs is being thrown off, so the if statement gets hit too early. You can also see this if you look at the character offsets of the word "Introduction" in the heading at the top of the 3rd page. You'll notice that the character offset is duplicated for a couple of letters, and is out of sync with the index of the character itself.
What I need is a script that will take a selection (of any type), and simply return the correct index of the paragraph containing it every time. It doesn't seem like a difficult thing to do, and since the paragraphs are accessible by index, they should be able to return their index to the user. I have a feeling Apple need to add this functionality to the Pages Applescript dictionary, and they definitely need to fix the bug where the character offsets go out of sync after embedded objects. These are really quite bad problems.Hi,
Pierre L. wrote:
I have tested it with the document referred to by andyboyd. When the first word (“Introduction”) of the first paragraph of page 3 is selected, your script returns {10}, while it returns {12} when the second word (“to”) of the same paragraph is selected.
Message was edited by: Pierre L.
Thanks Pierre.
Ok, the error is that I mixed the variable N and N1, during the renaming of variables
return N - 1 must be return N1 - 1 -- return the index
Here the corrected script :
set indexList to my getIndexOfLinesInSelection()
on getIndexOfLinesInSelection()
script o
property parOffsetList : {}
on getIndex(C)
tell application "Pages" to tell front document
set parOffsetList to character offset of paragraphs
set tc to count parOffsetList
repeat with N from 1 to tc
if N = tc then return tc -- it's the last paragraph
if (item N of parOffsetList) > C then
set N1 to N
repeat -- check the character offset of the selected line
if N1 = tc then return tc -- it's the last paragraph
select paragraph N1 -- select next paragraph
set sel to (get selection)
if class of sel is list then
repeat with aItem in sel -- this line contains text and object
try
if character offset of first character of aItem > C then return N1 - 1 -- return the index
exit repeat -- else character offset of the selection <= C , exit the repeat
end try -- error,aItem is not valid, continue the repeat
end repeat
else
try
if (character offset of first character of sel) > C then return N1 - 1 -- return the index
end try
end if
set N1 to N1 + 1
end repeat
end if
end repeat
end tell
end getIndex
end script
tell application "Pages" to tell front document
set sel to (get selection)
if class of sel is list then -- selection contains object or (Non-Continuous selection in the same line or in différents lines).
set charOffsetList to {}
repeat with aItem in sel
try
set end of charOffsetList to (character offset of aItem) -- get character offset of the valid item
end try
end repeat
else -- insertion point or the first line in continous text selection
set charOffsetList to {character offset of sel}
end if
if charOffsetList is {} then return {} -- no valid item in the selection
set indexList to {}
repeat with C in charOffsetList
set r to o's getIndex(C)
if r is not in indexList then set end of indexList to r
end repeat
return indexList
end tell
end getIndexOfLinesInSelection -
Need suggestion on Multi currency and Unicode character set use in ABAP
Hi All,
Need suggestion. In one of the requirement I saw 'multi-currency and Unicode character set experience in FICO'.
Can you please elaborate me how ABAPers are invlolved in multi currency as I think this is FICO fuctional area.
And also what is Unicode character set exp.? Please give me some document of you have any.
Thanks
Sreedevi
Moderator message - This isn't the place to prepare for interviews - thread locked
Edited by: Rob Burbank on Sep 17, 2009 4:45 PMUse the default parser.
By default, WebLogic Server is configured to use the default parser and transformer to parse and transform XML documents. The default parser and transformer are those included in the JDK 5.0.
The built-in WebLogic Server DOM factory implementation class is com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.
The DocumentBuilderFactory.newInstance method returns the built-in parser.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); -
I have noticed that this question has been asked a lot, but I am still not understanding. How do I move ALL of my music on iTunes into iCloud? I have subscribed to match and increased my iCloud storage. Only part of my music is in the Cloud and not on my iPhone.
Hello, Crafter Lady.
Thank you for visiting Apple Support Communities.
You may find this article helpful when troubleshooting issues with iTunes Match.
iTunes Store: Troubleshooting iTunes Match
http://support.apple.com/kb/ts4054
Cheers,
Jason H. -
My speakers are not working when I try to play music or when I get notifications buh when I go to sound and increase and decrease sound it works HELP
Clean iPhone charging port with a clean dry toothbrush. The iPhone port has a short, and falsely senses it is in a dock device.
-
I came up with a way to increase the bottom line and increase public opinion of Verizon.
When the Verizon customer service staff read script to customers all day, they know all the details... all the small details. The average user does not. Some people use Verizon email for important email, and then other email accounts for less important messages. There should be an option to pay a fee if the average user does not see any reason that Verizon would turn off email. Other companies have email.
Look at the ads for the Discover card in the subway. They read - Discover IT is New, IT is Different, IT is Human. Talk to a real person anytime you want. It will change the way you feel about ________.
What if Verizon changed. What if all the staff of Verizon, knowing that their Midyear reviews are coming suggested change. What if they could say "I came up with a multi-million dollar way to increase revenue." I came up with a way to increase the bottom line and increase public opinion of Verizon.
Give the customer a choice to pay $200 for a one time transfer of email. Then Verizon is a hero and makes money too. Multipy $200 by the number of people who had to give up internet this month and that number has to be big! Put that message on your midyear review. Nobody can tell where it came from. They will only know that you are trying to think of ways to increase the bottom line. Who knows... maybe there will be a raise in it for you! Good luck.Oh yes, this is great – At last, I can see what I’m trying to do at least. Appreciate your input so rapidly. I jump on the link so rapidly that I failed to notice if there might be a set half this much. I might be able to see it half this much increase like 100% instead of 200%? Oh don’t get me wrong. I’m not complaining, was just wondering – what if…
Thanks,
Sam -
Graphics drawString and then fillRect()
Hi,
I have a JPanel which displays Graphics. My Problem is I have some strings to be displayed in the panel with g.drawString() and surround each and every string with rectangle with some background. I know that it can be done in the other way that is first drawing the rectangle i.e, fillRect() and then draw the string. but, I need to do other way round, i.e, first display the string and surround it with rectangle with some background.
The above is a scenario in my project. somebody please help me in resolving this problem.
Thanks in advance,
with regards,
Dawood.Why would you need to do it that way round? - unless your text is less than 100% opaque and you need it to act as a "cutout" for the rectangle then it makes no difference.
The easist way (to the best of my knowledge) to render the rectangle around the text would be: to create a white off-screen image the same size as the rectangle, render the text to it in black, create a second image of the same size, fill that with your rectangle colour, and then use the former as an alpha mask for the latter, then slap the product onto your target image - which isn't hard to code but won't be fast, and is pretty pointless unless you're rendering the text as translucent... -
How to find Database, APPL_TOP and IANA character set on 11i?
Hi,
Could you please tell How to find out Database character set, APPL_TOP character set and IANA character set on existing 11i environment?
This is required to pass the input during R12 upgrade.
Regards,
AVDatabase:
SQL> select value
from V$NLS_PARAMETERS
where parameters='NLS_CHARACTERSET';
Application:
$ echo $NLS_LANG
IANA:
Check the value of "s_iana_cset" context variable in the context file or check the value of "ICX:Client IANA Encoding" profile option.
NLS Frequently Asked Questions [ID 399789.1]
Oracle Applications 11i Internationalization Guide [ID 333785.1]
How autconfig determines the value for Iana Charsets s_iana_cset value set in XML context file [ID 1380683.1]
Thanks,
Hussein -
Which program is better for reducing noise in photos and increasing sharpness?
Which program is better for reducing noise in photos and increasing sharpness?
And based on what criteria as in "Which program of [insert names here]?" and "What files?" ? Sorry, your post simply is not much use.
Mylenium -
SQL Server 2000 - Valid Binary datatype and valid character datatype:
SQL Server 2000 - Valid Binary datatype and valid character datatype:
Which is not a valid binary datatype :
BIT , IMAGE, TMESTAMP
Which is not a valid Character datatype :
VARTEXT , BLOB , TEXTBOL 2014: "
Data Types (Transact-SQL)
SQL Server 2014
Data Type Categories
Exact Numerics
bigint
numeric
bit
smallint
decimal
smallmoney
int
tinyint
money
Approximate Numerics
float
real
Date and Time
date
datetimeoffset
datetime2
smalldatetime
datetime
time
Character Strings
char
varchar
text
Unicode Character Strings
nchar
nvarchar
ntext
Binary Strings
binary
varbinary
image
Other Data Types
cursor
timestamp
hierarchyid
uniqueidentifier
sql_variant
xml
table
Spatial Types "
LINK: http://msdn.microsoft.com/en-us/library/ms187752.aspx
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
To delete first and last character of a string???
Hi Everybody !!!
Do you know a method that can permit to delete in a string the first and the last character?
For instance I have in my string this word : [the word]
I would like to delete the '[' and the ']' character.
Is exist a method that permit to delete this character?
Thanks !!!Look at the substring method of the String class.
Note that since string is immutable, you'll need to assign the results of substring to a variable (could be the same as the original or different). -
I use Aperture on my Mac and have approx 450Gigs of raw files for my photos and growing. I'm running short on space and system is starting to slow down. What are the best ooptions to improve performance and increase space space.?
important to note that what you are talking about is not a backup
It is simple to ahve your iPhoto library on an external drive -
Moving the iPhoto library is safe and simple - quit iPhoto and drag the iPhoto library intact as a single entity to the external drive - depress the option key and launch iPhoto using the "select library" option to point to the new location on the external drive - fully test it and then trash the old library on the internal drive (test one more time prior to emptying the trash)
And be sure that the External drive is formatted Mac OS extended (journaled) (iPhoto does not work with drives with other formats) and that it is always available prior to launching iPhoto
And backup soon and often - having your iPhoto library on an external drive is not a backup and if you are using Time Machine you need to check and be sure that TM is backing up your external drive
And you can have multiple i{Photo libraries - one can be on your internal drive and other on an external drive -- iPhoto Library Manager - http://www.fatcatsoftware.com/iplm/ - is a very helpful tool for managing multiple libraries
LN -
How to reduce costs and increase efficiency of pho...
Dear Skype community!
I need to find some information about how to reduce costs and increase efficiency of phone calls in sales organisation?
What are advantages of Skype contarry to the concurrence ? I'm Inside Sales manager SEMEA
Is there anyone who can explaine ?
thanks a lot !
Solved!
Go to Solution.Tilly_in_action,
Review the following link:
http://blogs.skype.com/2012/05/24/5-real-benefits-of-using-skype/
Thanks,
Kent C. -
Decreasing latency and increasing down/up speeds
My latency is usually between 30ms and 50ms. My speed is 2454kbps down and 350kbps up. It's really hard to do some good gaming at those speeds and especially with that kind of latency. I'm running through my wireless router. I'm on a Buffalo WHR-G54S Airstation Wirless-G. How can I decrease my latency and increase my speeds?
I am paying that extra money for the high speed. I should be getting at least 3500kbps/down and around 1200kbps/up. I tested my apartment neighbor's speeds and he tested out at 3200kbps/down and 900kbps/up, (latency only less by about 5ms on average), and we are on the same internet package. He's running on a pc with more than out of date equipment and I know my macbook should kick his pc's butt. Fine, forget the router and the wireless. Being hardwired into my modem, how can I achieve greater speeds and semi-more importantly, how can I decrease my latency time?
P.S. Is there a way to get the speeds I desire while being hardwired into the router? (Reason being because I like to play my 360 online as well, and I'm gettin some semi-bad lag everywhere I go). If not, I'll go hardwired permanently... until I get a better router of course.
Message was edited by: renen1987
Maybe you are looking for
-
Rendering web page into an image
is there any way to render a web page into a thumbnail image using java. please let me know if there are any...
-
I down loaded an illustrator trial on a computer I was borrowing from a friend, saved my work as an editable pdf and now when I try to re-open the file on my computer it says this file was generated by the newest version and I may lose information wh
-
Version Switches for Acrobat documents
When I read a PDF manual, such as the one for Lightroom 2, I am very irritated by the repetitive "Control X Windows Command X Mac" and such phrases. I think it is irritating and distracting enough to make it more difficult to learn the content. The
-
SE63 - Translating subscreen data
Dear Colleagues, i have translated the field labels for the data elements from DE to EN. The data elements belong to a subscreen. I logged in with language EN and checked the layout in screen painter. All labels are shown in language EN. But when i s
-
Hi, I am facing a peculiar problem. jobq slave waits are considered to be idle waits and should be ignored. But, on one of my 9205 production system, I see 80-90 sessions waiting on this event. Job_Queue_processes parameter is set to 100. Out of 80-9