• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overlapping Strings in DrawingPanel (JFrame)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For my APCS Project, we are trying to generate a wordcloud (google it if you don't know what these are. They're pretty cool.). The challange is, however, to display the words close together, without overlap. no matter what the length of the string is. Right now, we have basically simple hard-code, that is, panel.drawString(words.get(0) * 30 - words.get (0) * 12 + 20 - 122, ....); (given parameter ArrayList<String> words. Can anyone give us an algorithm to print out the words without overlap on a panel?
 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you'll use FontMetrics (google it if you don't know what these are. They're pretty cool.)
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TextLayout and LineBreakMeasurer can give you a closer fit. But be aware of a 1-pixel bug, don't know whether it's been fixed yet.
https://forums.oracle.com/forums/thread.jspa?threadID=1263979

Why don't you just use a JTextPane/JEditorPane?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic