Subscript in Strings


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Subscript in Strings

Hybrid View

  1. #1
    Join Date
    Jul 2004
    Posts
    6

    Subscript in Strings

    Hello.

    I want to draw Strings containing subscripts on designated places in my JFrame. I know you can use html-coding to get subscripts on for example buttons and textfields, but I can't use those since the placement have to be dynamic.
    The only option I've found is to check the string for numbers, then divide the string into substrings and draw each of these using different fonts. But I get a problem because it's very hard to calculate the length of a string in pixels.
    Is there a simpler solution?

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Could you give an example of what your trying to do?
    What is a String containing a subscript?
    String s = "array[x]"; // A string followed by a [ followed by a string followed by ]

    The FontMetrics class will give you pixel sizes of Strings.

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Why will YOU have to calculate the size of the string in pixels? Can't you use the Font class or the FontMetrics class to do all of this work for you?

    Define a font which is your subscript font. When appropriate, display using that font, then switch back to the "base" font.

Similar Threads

  1. Replies: 5
    Last Post: 06-19-2006, 09:48 AM
  2. PostBack while tracking Query strings
    By kashif_82 in forum ASP.NET
    Replies: 1
    Last Post: 07-26-2005, 08:23 AM
  3. Speaking of strings...
    By Harlow in forum .NET
    Replies: 246
    Last Post: 10-26-2002, 12:30 AM
  4. Allocating memory in VB (Custom strings)
    By Mark Alexander Bertenshaw in forum VB Classic
    Replies: 4
    Last Post: 03-04-2002, 07:04 AM
  5. Strings and memory management
    By Brian Leung in forum VB Classic
    Replies: 36
    Last Post: 09-18-2000, 09:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center