Swing's BasicHTML.createHTMLView metrics usage

I'm doing some graphics processing and HTML is a perfect choice for styling the displayed content. I'm trying to reuse swing's built in html support, and it works perfectly if I hard code the height passed to View.paint, but I can't figure out how to determine how tall the bounds of the rendered content would be at runtime given a specific width.

Graphics2D g = ... JLabel label = new JLabel("blah blah blah..."); View view = BasicHTML.createView(label, label.getText()); int minHeight = .... // Calculation magic goes here Rectangle htmlSize = new Rectangle(0, 0, 50, minHeight); g.setClip(htmlSize); view.paint(g, htmlSize);

If I ask the JLabel direction with getPreferredSize() it doesn't consider wrapping at all. If I try using a JEditorPane it returns a larger, but fixed size rectangle.

Thank you.

-------------Problems Reply------------

The height can't be calculated until the width is known. When dealing with Swing components I think you need to do something like:

component.setSize(100, 1);
Dimension size = component.getPreferredSize();

Or maybe you can use the concepts present in this posting:

Category:java Views:0 Time:2009-08-06

Related post

  • is there a book overviewing different types of source code metrics? 2010-02-06

    I have to submit a paper about the usage of source code metrics in software engineering processes. I thought it would be nice to start by introducing some categorization of source code metrics (for example using plane LOC count Vs doing some static a

  • find out if text of JLabel exceeds label size 2011-11-01

    In java when the text of the JLabel could not be displayed due to lack of space the text is truncated and "..." is added in the end. How can I easily find out if currently JLabel displays full text or the truncated? Thanks in advance. EDIT: I see tha

  • StringBounds of htmlized string 2010-01-20

    Is it possible to calculate the bounds of a htmlized String in Java Swing? I tried using the BasicHtml.createHTMLView, but kept getting the same prefSpan; irrespective of the component font. Regards, Pavan --------------Solutions------------- Is this

  • How can I replicate disabled appearance for a JCheckBox? 2010-06-28

    Take the following example code. There is some bug in Swing which doesn't render disabled components as disabled if the component contains HTML. Aside from reporting the issue, which I hope a colleague has already taken care of, is there some good wa

  • JRadioButton cannot be cast to JButton 2011-12-14

    I have actionPerformed() method which does two things: print out the radio buttons selected and set visibility of labels in another class. I get cannot be cast to error when the radio button is clicked. public void actionPerformed(ActionEvent e) { Sy

  • how to turn off windows 10 key logging? 2013-04-06

    How can we disable sending keyboard pressings to the ms? I agree to send anything but keyboard pressings. --------------Solutions------------- Reinstall win8.1 - if you agree to its terms. If Microsoft actually did use anything with peoples personal

  • Cross Platform System Usage Metrics 2010-02-13

    Is there a cross platform C API that can be used to get system usage metrics? --------------Solutions------------- I've worked with libstatgrab before. Gets you some pretty useful system statistics for the main Unix-like variants and Windows through

  • Is there a proved performance and memory usage benchmark on the SWT & Swing? 2010-03-04

    I want to know about SWT & Swing , memory usage and performance. which one has better performance and which one consumes less memory. Is there a proved benchmark on these measures or everybody with good experience in these fields. thanks --------

  • Eden space usage constantly increasing when using Swing 2012-03-19

    I'm a beginner in the domain of JVM, but I noticed that when Swing components are used, like JFrame, the Eden space usage constantly increases (at constant speed I suppose, since the graph plotted in VisualVM is a rising straight line), until the GC

  • Java Swing memory usage 2014-01-09

    There are plenty of questions on this issue, but no answer satisfied me; I'm coding a simple GUI window using Swing. Currently it only contains 4 buttons and one of them is opening a file chooser. When I use VisualVM Monitoring tool to look at memory

  • Java's swing print() usage 2011-02-10

    Does java's swing print() have to be called on the EDT (event dispatch thread)? It is taking an extended amount of time to execute and long running things being on the EDT are a pain, as we all know. --------------Solutions------------- Short answer,

  • What is the (event-dispatch) thread safe usage for JOptionPane.showMessageDialog and swing.utils.invokeAndWait? 2011-03-30

    I have a simple groovy script that from its main thread of execution needs to display some dialog boxes to the user. My swing knowledge is limited and rusty but I recall reading about the need to be careful to keep GUI stuff on the event-dispatching

  • Understanding Java Swing screen buffer memory usage (reading materials would be welcome) 2011-04-25

    So I need to understand how swing allocates memory for buffering screen rendering. Obviously there are duplicates if you have double/tripple/etc buffering. However I would need to know when swing allocates memory and how much of it. Very helpful to k

  • swing and jogl usage in a windowed application 2011-07-07

    I have a problem solving a problem concerning jogl and swing. i want to use jogl whit swing components but it doesn't refresh all the time. how can i repaint, refresh the opengl "image" in the swing component (update).when i change the position of my

  • Finding Memory Usage in Java 2009-02-17

    Following is the scenario i need to solve. I have struck with two solutions. I need to maintain a cache of data fetched from database to be shown on a Swing GUI. Whenever my JVM memory exceeds 70% of its allocated memory, i need to warn user regardin

  • Are there any good tools for finding usage statistics of GUI, broken down panes and components? 2010-01-13

    Collecting usage statistics per web-page on sites is common practice, I'm interested in a similar thing, but for GUI:s. You see Google Chrome (and others) collect usage statistics so Google can find out what features people use, to data-mine what see

  • How to monitor the computer's cpu, memory, and disk usage in Java? 2008-09-06

    I would like to monitor the following system information in Java: current cpu usage** (percent) available memory* (free/total) available disk space (free/total) *note that I mean overall memory available to the whole system, not just the JVM I'm look

  • How can you get database specific performance metrics for things like CPU/Memory/etc. in SQL Server 2005? 2008-09-18

    I have a couple databases on a shared SQL Server 2005 cluster instance, that I would like performance metrics on. I have some processes that run for a very long time and suspect that code inefficiencies, rather than insufficient hardware are to blame

  • Looking for a Swing Run-In-Background GUI library 2008-09-22

    Most modern apps provide an interactive way to push a long running operation onto a background queue. I am developing a swing application and I have implemented a simple "framework" to support that. However, I can't help but think that something like

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.144 (s). 11 q(s)