java - How to adjust JLabel dimensions to fixed font and font size? -


this question has answer here:

i trying make java swing application involves use of several jlabels. each jlabel have different set of text , font size, depending on program input. every label must take little excess space possible. how can calculate minimum possible width , height jlabel, given fixed string of text, fixed font, , variable font size? define minimum height , width smallest possible dimensions jlabel before "..." displayed in label. "..." auto-generated , indicates jlabel small text displayed.

for example: how narrow , short can jlabel contains text "hello world" written in 12 point tahoma font before label displays "..."?

    jlabel label = new jlabel("hello world");         label.setfont(new font("tahoma", font.plain, 12));         label.setbounds(100, 100, ???, ???);  //how calculate minimum possible width , height fit text? 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -