Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39333
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JLabel Text Cutoff |
| Date | 2020-03-04 21:39 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <r3p3mg$es5$1@dont-email.me> (permalink) |
| References | <c906ffa0-dddc-452b-8a59-afa3ace910d3@googlegroups.com> <r3ormf$rde$1@dont-email.me> <ff0d2533-50b2-4dbb-8e58-3b9b4abcc58c@googlegroups.com> |
On 2020-03-04 21:15, Eric Douglas wrote: > On Wednesday, March 4, 2020 at 1:23:22 PM UTC-5, Daniele Futtorovic wrote: >> The code you're looking for is in >> sun.swing.SwingUtilities2#clipString >> called by (ultimately) >> javax.swing.plaf.basic.BasicLabelUI#layout >> >> Looking at that method, I don't think there's any built-in way of having >> the clipping occur at the start of the string: >>> return string + clipString; >> always appends. >> > So there isn't a method that simply does that? > I would have thought that should be the default if the control isn't wide enough for the text and you tell it to align the text to the right side of the control. They probably could have added that -- and for all I know perhaps they have, somewhere. But in their defense, I wouldn't say that this kind of functionality should /obviously/ be there. The label clipping is really just a crutch. It doesn't make much sense for a label to be clipped in the first place -- and if your UI relies on that, I would say the fault is more with your UI. I found it at times (when I was still doing UIs) helpful to use the path of least resistance with respects to the library; mostly, they knew what they were doing, much more so, I found, than me. Don't underestimate how much UIs rely, to be effective, on paradigms and implicit assumptions. Lastly, note that what I've seen in the wild for labels that didn't fit their space, were animations to scroll the text back and forth (or looping around) through the available space. It's a bit trickier (since it involves background tasks), but works decently as a widget. > So the workaround I came up with sounds ugly. Seems fairly par for the course of Swing code to me. > final MyTextControl lbl_1 = lbl.new MyTextControl(); Ugh. Here's a tip: don't do this. Don't ever do this. I mean the qualified `new`. Make that inner class static. If you absolutely can't (and you always can), then create an instance method in the enclosing that returns a new instance of the inner class. But qualified new should be avoided IMO. -- DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JLabel Text Cutoff Eric Douglas <e.d.programmer@gmail.com> - 2020-03-04 10:06 -0800
Re: JLabel Text Cutoff Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-04 19:23 +0100
Re: JLabel Text Cutoff Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-04 19:23 +0100
Re: JLabel Text Cutoff Eric Douglas <e.d.programmer@gmail.com> - 2020-03-04 12:15 -0800
Re: JLabel Text Cutoff Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-04 21:39 +0100
Re: JLabel Text Cutoff Eric Douglas <e.d.programmer@gmail.com> - 2020-03-04 12:59 -0800
Re: JLabel Text Cutoff Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2020-03-04 22:26 +0100
Re: JLabel Text Cutoff Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-03-04 13:25 -0500
csiph-web