|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
What is the best way to get the width in pixels of a string?
How would I go about determining the size in pixels of a string with Java calls? I'm not familiar enough with Java and the way I was trying to get it (with java.awt.FontMetrics) doesn't work. I'm assuming that is because it is an abstract class. So how else could I do this from within Studio.
Thank you for any suggestions. BobP. P.S. I'm trying to implement a scrollable text input. I've got it working with a character count of the string but would like to get down to the pixel level if it is possible. |
#2
|
||||
|
||||
I don't know but I think it was nielm who actually posted an STV that had examples of acual scroll bars in Sage TV. This had scrolling panels, scrolling tables, multi column and wrapping. Might this help you?
Scrollbars Gerry
__________________
Big Gerr _______ Server - WHS 2011: Sage 7.1.9 - 1 x HD Prime and 2 x HDHomeRun - Intel Atom D525 1.6 GHz, Acer Easystore, RAM 4 GB, 4 x 2TB hotswap drives, 1 x 2TB USB ext Clients: 2 x PC Clients, 1 x HD300, 2 x HD-200, 1 x HD-100 DEV Client: Win 7 Ultimate 64 bit - AMD 64 x2 6000+, Gigabyte GA-MA790GP-DS4H MB, RAM 4GB, HD OS:500GB, DATA:1 x 500GB, Pace RGN STB. Last edited by gplasky; 01-20-2007 at 02:27 PM. |
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
OK I figured a way to make my idea work with one exception. It appears that at 640x480 the font size is ruffly the same as the equivalent in WordPad. But it is obvious that the font is enlarged when going to full screen or reduced when going to 320x240. So my question is what is the ratio used? Because the letters at 320x240 are not 1/2 half size and the letters at 1280x960 are not 2x the size.
Thoughts? BobP. |
#5
|
|||
|
|||
I thought I would post the solution I found for this in case anybody was interested:
Code:
public static int getTextWidth(String text, String fontName, String fontStyle, int fontSize, int screenWidth) { float size = (screenWidth / 640.0F) * fontSize; java.awt.Font font = java.awt.Font.decode(fontName + "-" + fontStyle + "-" + fontSize); font = font.deriveFont(size); java.awt.Label label = new java.awt.Label(text); java.awt.FontMetrics fm = label.getFontMetrics(font); int width = fm.stringWidth(text); return width; }
BobP. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|