Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.gui Subject: Re: JTabbedPane fails to clip tab text Date: Tue, 05 Mar 2013 12:47:13 -0800 Organization: A noiseless patient Spider Lines: 86 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 5 Mar 2013 20:45:47 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9d780cfe5f3a46943b6de66101ca6894"; logging-data="30403"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Lqtx3jd5d0y5F47WuuqSR" User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: Cancel-Lock: sha1:+ZHG3cb4rFKgzReLoIBJjdktjAM= Xref: csiph.com comp.lang.java.gui:5307 The text isn't going to shrink just the tabs. So if you shrink the container that the tabs are in to a point where the text is too big for what's left of the tab then it is going to write beyond the tab. Make a smaller label or a bigger container. knute... On 3/5/2013 10:51, FredK wrote: > I have a JTabbedPane with multiple tabs, using WRAP_TAB_LAYOUT. > When the user shrinks the window, the longest tab label draws its > text outside the tab area instead of clipping it. It even runs > over into the next tab. > > Also, when using Numbus LAF, it does not size properly. > What am I missing to get this to work properly? > > Here is a short code sample: > > import java.awt.BorderLayout; > import java.awt.event.WindowAdapter; > import java.awt.event.WindowEvent; > > import javax.swing.BorderFactory; > import javax.swing.JFrame; > import javax.swing.JLabel; > import javax.swing.JPanel; > import javax.swing.JTabbedPane; > import javax.swing.UIManager; > import javax.swing.UIManager.LookAndFeelInfo; > > public class Tester extends JPanel { > > public Tester() { > setLayout( new BorderLayout() ); > setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); > > JTabbedPane pane = new JTabbedPane( JTabbedPane.TOP, > JTabbedPane.WRAP_TAB_LAYOUT ); > pane.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); > > JLabel p1 = new JLabel( "p1" ); > pane.addTab( "this is tab number 1, long label", p1 ); > JLabel p2 = new JLabel( "p2" ); > pane.addTab( "tab number 2", p2 ); > JLabel p3 = new JLabel( "p3" ); > pane.addTab( "this is tab 3", p3 ); > JLabel p4 = new JLabel( "p4" ); > pane.addTab( "tab 4", p4 ); > JLabel p5 = new JLabel( "p5" ); > pane.addTab( "another tab", p5 ); > > add( pane, BorderLayout.CENTER ); > } > > public static void main( String[] args ) { > try { > for ( LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() ) { > if ( "Nimbus".equals( info.getName() ) ) { > UIManager.setLookAndFeel( info.getClassName() ); > break; > } > } > } catch ( Exception e ) { > System.out.println( "No nimbus found" ); > } > > javax.swing.SwingUtilities.invokeLater( new Runnable() { > public void run() { > JFrame frame = new JFrame( "Tester" ); > frame.addWindowListener( new WindowAdapter() { > @Override > public void windowClosing( WindowEvent e ) { > System.exit( 0 ); > } > } ); > > Tester t = new Tester(); > frame.add( t ); > frame.pack(); > frame.setVisible( true ); > } > } ); > } > } >