Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39329

Re: JLabel Text Cutoff

From Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: JLabel Text Cutoff
Date 2020-03-04 19:23 +0100
Organization A noiseless patient Spider
Message-ID <r3ormf$rde$1@dont-email.me> (permalink)
References <c906ffa0-dddc-452b-8a59-afa3ace910d3@googlegroups.com>

Show all headers | 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


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