Determining the actual length of a string based on pixels?
How would you determine the actual length of a string based on pixels? Reason for is because a length of a string containing all " l " chars would be a lot smaller then the length of a string containing all "H" chars based on pixel width.
thanks,
newbie
Yes, look at the FontMetrics class which has methods to do just that. To get a relevant FontMetrics object, try "x.getFontMetrics(f)" where x is a Component and f is the Font your string is represented in.
Similar Messages
-
Hello, I am working on a SAP CRM 7 Sales implementation and we are implementing leads and opportunity scenarios. The current business organization model is that there multiple vertical and horizontal departments. This is typical matrix structure. This organization has done the segregation of its clients based on the verticals so every clients belongs to at least one or more Vertical department but Horizontal departments can contact all the clients. In the same way sales executives are also either belonging to one or more Verticals or Horizontal departments? Horizontal sales executive can create leads for any clients available in the system but a Vertical sales executive can only create lead only for the client belongs to his vertical and assigned to him. This can be achieved by creating organization structure and business partner relationship.
Now the problem statement is that few sales executives need work for both some Verticals and Horizontals at the same time. But requirement is that they should be able to do the both roles with single user id but multiple roles. So when sales executive is creating leads his vertical department, he should only be able to select clients assigned to his Vertical only but when he is creating lead for Horizontal department, he should be able to select any clients.
So Can I determine the business partners linked to user based on the assigned role and org. structure?
Please let me know if this is not clear also note we are only using CRM WebUI no SAP ePortal.
Thanks a lot your help in advance.
Regards
Sudesh SharmaThanks, Tahir
my problem has solved
Kind Regards,
Faisal -
How to Determine the Actual Bandwidth Utilization
Router A (Serial Port) in location A is connected to Router B (Serial Port) in location B through an IP VPN connection. How will I be able to determine the actual bandwidth utilization of the link between Router A and Router B?
Thankshi
Pls check this link which can help u out to configure and analyse/find out the actual usage of the bandwidth on both th sides of your location.
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
regds -
How to determine the character encoding of a string
I'm under the impression (however misguided this may be) that one of our Databases (it is set to 8859) is outputting it's values as 8859 charset to Java, who in turn is preserving this encoding.
Printout on the contents of data.get(info) yields garbage.
However, Doing
value = new String((data.get(info).getBytes("ISO-8859-1")), "UTF-8");and printing 'value' yields the proper Asian characters.
Is there a way to determine the Charset of a string somehow?Whereas some database drivers for other languages (C,
C++) make it possible to set the encoding on the
client side irrespectively to the database encoding
setting. So you can skew your database with those
programs.Some JDBC drivers allow one to specify the encoding as part of the connection URL. This may be a general property of JDBC drivers but, since I have now retired, my JDBC knowledge is getting as dated as I am so I don't really know. -
Length of a string (text) in pixels.
I'm trying to locate a String's center on an exact position, drawing it to a JPanel. But since i don't know the exact length of the string, it's not that easy. Can anybody help me out there?
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
public class CenteringStrings
public static void main(String[] args)
StringDemoPanel demo = new StringDemoPanel();
DemoActionPanel action = new DemoActionPanel(demo);
JFrame f = new JFrame("Centering Strings");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(action, "East");
f.getContentPane().add(demo);
f.setSize(500,300);
f.setLocation(200,200);
f.setVisible(true);
class StringDemoPanel extends JPanel
String text;
Font font;
final int
ASCENT = 0,
DESCENT = 1,
LEADING = 2,
BASELINE = 3;
int index = -1;
boolean sizeFlag, boundsFlag;
public StringDemoPanel()
text = "Centered text";
font = new Font("lucida sans oblique", Font.PLAIN, 36);
sizeFlag = false;
boundsFlag = false;
setBackground(Color.white);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
LineMetrics lm = font.getLineMetrics(text, frc);
TextLayout tl = new TextLayout(text, font, frc);
int w = getWidth();
int h = getHeight();
float textWidth = (float)font.getStringBounds(text, frc).getWidth();
float ascent = lm.getAscent();
float descent = lm.getDescent();
float leading = lm.getLeading();
float height = lm.getHeight();
float x = (w - textWidth)/2;
float y = (h + height)/2 - descent;
g2.drawString(text, x, y);
// marker for string origin (x,y) on baseline
//g2.setPaint(Color.blue);
//g2.fill(new Ellipse2D.Double(x - 1, y - 1, 2, 2));
// physical space of text
Rectangle2D textSize = tl.getBounds();
textSize.setFrame(x, y - textSize.getHeight(),
textSize.getWidth(), textSize.getHeight());
// string bounds
Rectangle2D bounds = font.getStringBounds(text, frc);
bounds.setFrame(x, y - ascent - leading, bounds.getWidth(), bounds.getHeight());
switch(index)
case ASCENT:
Rectangle2D r1 = new Rectangle2D.Double(x, y - ascent, textWidth, ascent);
g2.setPaint(Color.magenta);
g2.draw(r1);
break;
case DESCENT:
Rectangle2D r2 = new Rectangle2D.Double(x , y, textWidth, descent);
g2.setPaint(Color.orange);
g2.draw(r2);
break;
case LEADING:
Rectangle2D r3 = new Rectangle2D.Double(x, y - ascent - leading,
textWidth, leading);
g2.setPaint(Color.yellow);
g2.draw(r3);
break;
case BASELINE:
Line2D line = new Line2D.Double(x, y, x + textWidth, y);
g2.setPaint(Color.blue);
g2.draw(line);
if(sizeFlag)
g2.setPaint(Color.green);
g2.draw(textSize);
System.out.println("above size = " + (int)textSize.getY() + "\n" +
"below size = " +
(int)(h - (textSize.getY() + textSize.getHeight())));
if(boundsFlag)
g2.setPaint(Color.red);
g2.draw(bounds);
System.out.println("above bounds = " + (int)bounds.getY() + "\n" +
"below bounds = " +
(int)(h - (bounds.getY() + bounds.getHeight())));
public void setIndex(int i)
index = i;
repaint();
public void setSizeFlag(boolean flag)
sizeFlag = flag;
repaint();
public void setBoundsFlag(boolean flag)
boundsFlag = flag;
repaint();
class DemoActionPanel extends JPanel
StringDemoPanel sdp;
JRadioButton
ascentButton, descentButton, leadingButton, baselineButton, clearButton;
JRadioButton[] buttons;
JCheckBox
sizeCheck, boundsCheck;
JCheckBox[] checks;
public DemoActionPanel(StringDemoPanel p)
sdp = p;
createComponents();
private void createComponents()
ascentButton = new JRadioButton("ascent");
descentButton = new JRadioButton("descent");
leadingButton = new JRadioButton("leading");
baselineButton = new JRadioButton("baseline");
clearButton = new JRadioButton("clear");
buttons = new JRadioButton[] {
ascentButton, descentButton, leadingButton, baselineButton, clearButton
ButtonGroup group = new ButtonGroup();
RadioButtonListener buttonListener = new RadioButtonListener();
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weighty = 1.0;
gbc.insets = new Insets(2,2,2,2);
gbc.gridwidth = gbc.REMAINDER;
gbc.anchor = gbc.WEST;
for(int i = 0; i < buttons.length; i++)
add(buttons, gbc);
group.add(buttons[i]);
buttons[i].addActionListener(buttonListener);
sizeCheck = new JCheckBox("text size");
boundsCheck = new JCheckBox("bounds");
checks = new JCheckBox[] { sizeCheck, boundsCheck };
CheckBoxListener checkBoxListener = new CheckBoxListener();
for(int i = 0; i < checks.length; i++)
add(checks[i], gbc);
checks[i].addActionListener(checkBoxListener);
private class RadioButtonListener implements ActionListener
public void actionPerformed(ActionEvent e)
JRadioButton button = (JRadioButton)e.getSource();
if(button == clearButton)
sdp.setIndex(-1);
return;
for(int i = 0; i < buttons.length; i++)
if(button == buttons[i])
sdp.setIndex(i);
break;
private class CheckBoxListener implements ActionListener
public void actionPerformed(ActionEvent e)
JCheckBox checkBox = (JCheckBox)e.getSource();
if(checkBox == sizeCheck)
sdp.setSizeFlag(sizeCheck.isSelected());
if(checkBox == boundsCheck)
sdp.setBoundsFlag(boundsCheck.isSelected()); -
My recent import from my camera into imove resulted in the entire video being seperated into many equal lengh mini clips with a duration of 0.01 seconds. When playining through these it is sped to quick to even see what is going on. What happened to cause this?
('cause then i can walk away and it makes the separate shoots into separate clips .. instead of having to sit at FCP for hours to log them individually)
FPC has a feature called DV Start/Stop Detect. You can Cature Now an entire tape and run the Start/Stop detect and it will separate each of your clips based on the metedata. It will recognize each individual time you started then stopped recording by placing a marker at the beginning of each clip. Then you drop all the markered shots into a new bin and it makes subclips out of them. Easy. You can read more about it in the manual. It's a very helpful tool. -
About the actual length of domain AUART
Hi experts:
please refer to below code:
REPORT TEST1.
DATA : abc(4) TYPE c.
DATA : XYZ TYPE VBAK-VKORG.
DATA : XYZ1 TYPE AUART.
abc = 'amit'.
xyz = 'abcd'.
xyz1 = 'xxxx'.
write:/001(01) SY-VLINE NO-GAP,
002(10) abc centered,
012(01) SY-VLINE NO-GAP,
013(10) xyz centered,
023(01) SY-VLINE NO-GAP,
024(10) xyz1 centered,
034(01) SY-VLINE NO-GAP.
Could anyone kindly suggest why the third 'centered' does not work?
I suppose it was caused by the length of AUART, but cannot prove it.
Can anyone help? Many thanks.Hi,
Here in your example the position specified having precedence over centered .
The first two centered are occuring due to only the position specified with them .
You can write the third field as centered as follows changing the position value -
DATA : abc(4) TYPE c.
DATA : XYZ TYPE VBAK-VKORG.
DATA : XYZ1 TYPE AUART.
abc = 'amit'.
xyz = 'abcd'.
xyz1 = 'xxxx'.
write:/001(01) SY-VLINE NO-GAP,
002(10) abc centered,
012(01) SY-VLINE NO-GAP,
013(10) xyz centered,
023(01) SY-VLINE NO-GAP,
*****024(10) xyz1 centered,
026(10) xyz1 centered,
034(01) SY-VLINE NO-GAP.
Here I have changed the position of the third field from 024 to 026. Now It is working.
Regards
Pinaki
Edited by: Pinaki Mukherjee on Feb 10, 2009 5:20 AM -
How to determine the length of a LRAW field
Hi
I'm trying to write a generic persistency class that saves data in a table with a lraw field.
As required the lraw field must be preceded by a length field of type INT2, but how can I calculate the actual length of the lraw field?
kind regards ThomasHi Martin
I'm sorry to tell you that you are wrong. The INT2 field must contain the actual length.
I have a table with a LRAW of 1024 bytes, but if I put 15 to the length field, then only 15 bytes are stored in the database.
Of course I could just enter 1024 for the length, but that would wast a lot of database space - and performance.
My class has a persistency method that inserts or updates a record in the database. The data that should be stored in the LRAW is sent to the method via a pointer (field symbol) of type X. This pointer can point at any data type.
Something like this:
field-symbols: <input> type x.
field-symbols: <lraw> type x.
*assign any field to <input>
assign <lraw> to mydbtable-lraw_field casting.
<lraw> = <input>.
*here i need to determine the length of mydbtable-lraw_field before i store the content to the database.
By debugging I can tell that if the pointer points to a char 32 field then the length of the X pointer is 64 and if the pointer points to a timestamp then the length of the x pointer is 8, but how can I determine this length programmatically - either from the x pointer or from the LRAW?
Best regards
Thomas -
How can I determine the device number from the task ID
I'm using 'Port Config' to initialize my DIO port for a NI-DAQ 6052E. Port Config returns a task id and it would be very useful if I could determine what device number I have based on the task id.
Hello,
Thank you for contacting National Instruments.
It is not possible to determine the device number programmatically from the task id. This would be slightly redundant since you must supply a device number when you Port Config executes. You could simply create a local variable of the Device Number control that is connected to the Port Config.vi if you need to use the device number elsewhere in your VI. Simply right-click on the Device number control and select Create >> Local Variable. Then right click on the local variable and select change to read. This will allow you to read the value of the device number you provided anywhere in your VI.
If you would rather determine the actual device that is being used rather than the device number, yo
u can use the Get DAQ Device Info.vi. I have attached a simple example program that demonstrates how to use the VI.
Regards,
Bill B
Applications Engineer
National Instruments
Attachments:
Write_to_1_Dig_Port_(E).vi 58 KB -
When generating an accountId - I append a numeric onto the end of a derived string.
I need to determine the overall length of the accountId because I have a size limit. However, when I try to get the length of a numeric string (like "17") I get 0 - see the following trace.
<set name='numericLength'>
<length>
<ref>numeric</ref> -->17
</length> -->0
</set> --> nullcouldnt you concat your numeric value with a single character string and then
subract 1. I believe XPRESS converts integers to string equivalents when doing "string" type manipulations.
i.e.
get your integer value in variable numeric
<set name='numericLengthplus1'>
<length>
<concat>
<s>0</s>
<ref>numeric</ref>
</concat>
</length>
</set>
set name='numericLength'>
<sub>
<ref>numericLengthplus1</ref>
<i>1</i>
</sub>
</set> -
How to determine the kernel compilation time stamp ?
Hi, all
sorry of this is a miss post.
I'm trying to find out the date (time stamp) using the
"uname -a" command , but I'm not sure this is the correct way , because the
the output of the command returns the kernel release date and I'm not sure this is the
correct time
Any suggestions ?
VictorI'm referring to the date the kernel was actually compiled .
My question was if the output of the command "uname -a" contains the kernel compilation date, because
the "man uname" and "info uname" says that the output contains kernel release info.
Or is there another way of determining the actual date(time) when the kernel was compiled. -
Selecting actual length of data
i am selecting from a txt file, but say this particular field in the txt file is varchar2(30), but the actual length of the data can vary, how do i select the actual length of the data,instead of getting the data followed by spaces?
Hi Justin,
It more like this.
I am using the utl_fle to retrive data from a txt file.
So say the length in the txt field is 30 characted.
I have retrieved it using the utl_file and put it in variable A.
But the data in variable A does not have 30 characters, it may vary depending on the data in the txt file.
So how can i retrive the exact length of the data from the txt file,
eg of txt data(each field is 30 char long, but actual data length is only six
123123 123123 123123
But when i retriev from utl_file its comes out as
123123xxxxxxx
xxx denotes spaces, so how do i just retreive 123123.
The exact length of the records is random.Hope this is clearer. -
Whats the maximum length array and why?
Whats the maximum length array and why?
I tryed to search the forum but most people was wondering about the maximun length of a String..for(int i =20;i<=32;i++) {
try {
int[] p = new int[(int)Math.pow(2,i)];
pause(2000); // So that gc doesn't clean away the array before
// The OS memory manager gets to update.
System.out.println("Paused! i: " + i);
} catch(OutOfMemoryError e) {
System.out.println("Ex!!");
pause(10000); // Same sa before.
void pause(int p) {
try {
Thread.sleep(p);
} catch (Exception e) {}
}I worte this little code to test this.
It runs to 2^23 for me.
I am running
AMD Athlon, 512 DDR, Windows 2000 SP4
java version "1.5.0-beta2"
Java was using 42116 Kb RAM and 54632 Kb Swap when its at 2^23 -
How to determine the length of variable based on the character contents
Hi Experts,
I need to determine the length of variable based on the character contents I am looking for.
Example;
lv = 'FENCE - Construction bond'
Where I need to know the exact field length of 'FENCE -'.
It's possible that variable will have different values in different lengths.
Thanks.
KathKathy Amion ,
hello Will you please elaborate ...!
The suggestion for your proble as i understood it is you will have to split the string at seperator '-' in two say variable name and conten. and then you will calculate the length of the VARIable name by using string function. -
How to determine the maximum allowable length of a filename for Window ?
Hi all,
Could I know how to determine the allowable file length (the length of the absolute path) for a file in Window environment?
Due to some reason, I generated a zip file with a very long filename ( > 170) and put in a folder(the length of the folder path around 90). The length of the absolute path is around 260.
I used FileOutputStream with the ZipOutputStream to write out the zip file. Everything is working fine while i generating the zip file.
However, while i try to extract some files from the zip file i just created, i encountered the error
java.util.zip.ZipException The filename is too long.
I am using the class ZipFile to extract the files from the zip file like the following
String absPath = "A very long filepath which exceed 260";
ZipFile zipF = new ZipFile(absPath); //<-- here is the root causeIs it possible to pre-determine the maximum allowable filepath length prior i generate the zip file ? This is weird since i got no error while i created the zip file, but have problem in extracting the zip file ......
ThanksAssuming you could determine the max, what would you do about it? I'd say you should just assume it will be successful, but accommodate (handle) the possible exception gracefully. Either way you're going to have to handle it as an "exception", whether you "catch" an actual "Exception" object and deal with that, or manually deal with the length exceeding the max.
Maybe you are looking for
-
Learn how to organize your images in Lightroom using the Folder panel so that finding, moving and editing your images is a breeze. http://adobe.ly/12t0KCm
-
Photoshop CS 5.0 64/32 bit issues
Hey guys I'm having a issue while trying to download photoshop cs 5.0. It says that I need to be using a 64 or 32 bit operating system while I already am on one. I'm using Windows 7 Home Edition... Help please?
-
I POD WILL NOT WORK!! NEED HELP!!!
My I pod will not sync up with i tunes but when ever i plug it in a little box comes up on the compter saying that files could not be saved and to look for them somewhere else. it is 2nd generation and i have had it for 2 years and it has never done
-
Update Upper row column value in null column in sql 2008
Hi All, I want to update Upper row value into lower null value column dynamically . i have 10000 record . any one have sql query or any idea.Please help Akhilesh Sahu Sr.Software Developer
-
A frame failed to render while using Render Multiple Frames Simultaneously
Hello fellow AE users: I've read other threads which deal with this issue, however they don't seem to be exactly what I'm experiencing so I'm starting a new thread. I did do several hours of due diligence by research others' handling of this issue, s