Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39329
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JLabel Text Cutoff |
| Date | Wed, 4 Mar 2020 19:23:00 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 47 |
| Message-ID | <r3ormf$rde$1@dont-email.me> (permalink) |
| References | <c906ffa0-dddc-452b-8a59-afa3ace910d3@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 4 Mar 2020 18:23:11 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="f266e2671bb7c551a3637676b41240dc"; logging-data="28078"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QIjS3VuNZYTzRqZTMVH8i" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
| Cancel-Lock | sha1:n423efp7Sn/OnThgJbwtrh9cdh4= |
| In-Reply-To | <c906ffa0-dddc-452b-8a59-afa3ace910d3@googlegroups.com> |
| X-Antivirus-Status | Clean |
| Content-Language | en-US |
| X-Antivirus | AVG (VPS 200304-0, 03/04/2020), Outbound message |
| Xref | csiph.com comp.lang.java.programmer:39329 |
Show key headers only | View raw
On 2020-03-04 19:06, Eric Douglas wrote:
> Is there an easy way to show text on a JLabel cutoff from the left?
> I've tried every method and parameter I can think of but when the text runs out of the control it just wants to cut it off from the right.
> sample:
> import java.awt.Dimension;
> import java.awt.FlowLayout;
>
> import javax.swing.JFrame;
> import javax.swing.JLabel;
> import javax.swing.SwingConstants;
>
> public class TestLabel {
>
> public static void main(String[] args) {
> JFrame f = new JFrame();
> f.setPreferredSize(new Dimension(600,480));
> f.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
> String text = "too long text to fit in control";
>
> JLabel lbl_1 = new JLabel();
> lbl_1.setPreferredSize(new Dimension(70,20));
> lbl_1.setHorizontalAlignment(SwingConstants.TRAILING);
> lbl_1.setText(text);
> f.getContentPane().add(lbl_1);
>
> f.pack();
> f.setVisible(true);
> }
> }
>
> I see text displayed as "too long te..."
> I want to see text displayed like "...in control"
>
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.
--
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