0

zk label text trimming based on cell width

asked 2014-04-09 19:33:40 +0800

udayabaski gravatar image udayabaski
29 1

Hi, Is there any way to trim down the text based on the cell width.

In Grid, we have cells and label inside the cell. I want to display the text( with no-wrap ) based on the cell width. If the cell width gets increased, i want to display more chars and when decreases need to decrease the text. Basically the text should fit to the cell in a single line like we have in excel.

Thanks, Baskar.S

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-04-14 07:55:43 +0800

IngoB gravatar image IngoB flag of Germany
256 6

One way is to calculate the string-width in pixel and adjust your column-width.

public static Double calcWidthOfString(String input) {
    Font f = new Font(DEFAULT_FONT, Font.PLAIN, DEFAULT_FONT_SIZE);
    Rectangle2D r = f.getStringBounds(input, new FontRenderContext(null, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT));
    return r.getWidth() + COLUMN_MARGIN;
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-04-09 19:33:40 +0800

Seen: 21 times

Last updated: Apr 14 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More