Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: When resizing text to fill a JLabel the text sometimes "jiggles", how do I fix this? Date: Fri, 9 Dec 2016 21:22:17 -0000 (UTC) Organization: A noiseless patient Spider Lines: 32 Message-ID: References: <75624c6e-6a78-4e8a-82a4-4ff2556cc241@googlegroups.com> <5bda0936-09ee-4eea-8001-e0ad17f31b0b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 9 Dec 2016 21:22:17 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e7f8c8ea7f678ad98dfb2c90510f2ed"; logging-data="4227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PX1P56K4spkUTLeKiMQqSTxIYOoURe9c=" User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e git.gnome.org/git/pan2) Cancel-Lock: sha1:9jdo7wK6Cz8oRGBKB87zn0jpQzs= Xref: csiph.com comp.lang.java.programmer:36079 When I've needed to do something like this, my outermost GUI container (a JPanel) has been sized to fit the screen (size expressed in pixels). All labels, Text areas, etc are auto-scaled to match by expressing their sizes as percentages of the outermost container and the font scaled to match: during initialisation I construct a font with that size and use it everywhere, the benefit being that I don't need to resize and fonts after the program has been initialised. Modified Font construction is easy: import java.awt.Font; public class MyFont extends Font { private int fontsize; /* in pts */ public EditFont(int fontsize) { super("Monospaced", PLAIN, fontsize); this.fontsize = fontsize; } } ...and add any other methods you need in order to size a JLabel, etc, to contain a given string. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |