JTabbedPane using a JLabel in setTabComponent

Hi,
I am in front of a problem with the JTabbedPane and the setTabComponent function. I want to use a specific JLabel in the tab. I have done this but I have pointed out that using the setToolTipText on my JLabel prevent me from browsing the tab by clicking on the label (in the tab).
I just want to know if there is a way to fix this?
Here is an example :
public class test extends JFrame
    public test()
        JTabbedPane pane = new JTabbedPane();
        pane.add( "Tab1", new JLabel( "Tab1" ) );
        pane.add( "Tab2", new JLabel( "Tab2" ) );
        pane.add( "Tab3", new JLabel( "Tab3" ) );
        JLabel notClickableTab = new JLabel( "notClickableTab" );
        notClickableTab.setToolTipText( "notClickableTab" );
        pane.setTabComponentAt( 1, notClickableTab );
        JLabel clickableTab = new JLabel( "clickableTab" );
        pane.setTabComponentAt( 2, clickableTab );
        getContentPane().add( pane );
        getContentPane().setPreferredSize( new Dimension( 200, 200 ) );
        pack();
        setVisible( true );
    public static void main( String[] args )
        new test();
}I hope this is understandable :)

Don't set the tooltip?With this post I only want to see if there is something to do with that. In fact some property to set or anything like that , to correct that behavior.
Obviously, not setting the tooltip can be a solution, but this is not the result i want.
I already manage to find out some workaround using a mouseListener, but it may not be a solution in other circumstances.
Anyway, thanks for the "tip" :P

Similar Messages

  • Dynamic JTabbedPane using Reflection

    Hi all,
    First time posting... I am wanting to created a dynamic JTabbedPane that creates its tabs with dynamic objects, these objects are defined at runtime. I have searched the forums and got this far but I am having trouble with casting the Method object to a type of Component which is what is required by the add(String str,Component comp) ;
    I know that I have given it a paramater of type Method, I am not sure though how to cast it to a type Component. The strings "myClassName" and "myTabTitle" have only been used for the purpose of this post.
    Some more background information that might be usefull is the .getInstance() method that I am trying to invoke .. the SamConfigPanel class extends a custom abstract class that is of type JPanel.
    My code is posted below ... any thoughts??
    public static final SamConfigPanel getInstance()
    if (samConfigPanel == null)
    samConfigPanel = new SamConfigPanel();
    return samConfigPanel;
    Class cls;
    JTabbedPane iTabs = new JTabbedPane();
    try
    cls = Class.forName("myclassName");
    Method method = cls.getMethod("getInstance",new Class[0]);
    method.setAccessible(true);
    method.invoke(cls, new Object[0]);
    // testing for instance of my dynamic class
    boolean b2 = cls.isInstance(SamConfigPanel.getInstance());
    System.out.println(b2);
    iTabs.add("myTabTitle",method.invoke(cls, new Object[0]));
    catch(ClassNotFoundException e)
    System.out.println(e.toString());
    catch(NoSuchMethodException e)
    System.out.println(e.toString());
    catch(IllegalAccessException e)
    System.out.println(e.toString());
    catch(InvocationTargetException e)
    System.out.println(e.toString());
    }

    as long as you're shure that your method returns a component it's safe to cast.
    if you can't be shure, you'd have to check the return type of your method before invoking directly.
    or invoke the method first, then check the object.
    Object o = method.invoke(null, new Object[0]);
    if ( o instanceof Component)
            iTabs.add(keys,(Component)o);
    else
           //do something else, print warning or such

  • Can i use a jlabel on a panel then place gifs, on top of that jlabel?

    im doing a project that requires a 10x10 board and found a picture that is exactly the size i need 400x400, can i place the background (gif file) on a jlabel then place it on my boardPanel, then on top of that place images on the board accordingly? or is there more useful and better way? or do i have to use Mediatracker for both the background image and the placing of pieces. any suggestions or tutorials on this, its my first time making a board and making the pieces movable on the it.
    thanks in advance!

    have to use Mediatracker for both the background image and the placing of piecesMediaTracker has nothing to do with the placing of images. It is only used to read the image file. Actually I believe the newest recommendation is to use the ImageIO class to read image files.
    Heres one way to use an image as a background that might work for you since it appears that your background image will be the same size as your game board.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class LabelPanel extends JFrame
         public LabelPanel()
              JLabel label =  new JLabel( new ImageIcon("????.jpg") );
              label.setLayout( new GridLayout(4,4) );
              getContentPane().add(label);
              for (int i = 0; i < 16; i++)
                   JPanel panel = new JPanel();
                   panel.setOpaque( false );
                   panel.setBorder( new LineBorder(Color.RED) );
                   label.add( panel );
         public static void main(String[] args)
              LabelPanel frame = new LabelPanel();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }For other ideas you can search the forum using "background image" as keywords if I remember correctly.

  • Loading JPEG/Gif images causes Out Of Memory Error

    Hello Java gurus, please shed some light on this.....
    I am not a java newbie, but I am a java newbie in the area of dealing with graphics. I am using JDK 1.4.2_01 on Win XP with 2.4ghz and 512 RAM. When I try to read in a (or a few) JPEG image into a JLabel using ImageIcon, I get an out of memory error everytime. This happens whether I am reading the image out of a jar file or out of a local directory. The JPEG's are 8.5" x 11", and range between 150kb to 900kb. I am trying to load approximately 10 images in a JTabbedPane using new JLabel(ImageIcon) on individual JPanels (one JPanel for each JPEG). Now I get the java.lang.outofmemory error whether I try to load 1 image or 10 images. Anyone got a clue as to what I am doing wrong? I actually do get one image loaded before the error gets thrown. So I do know that it is trying to load the right image. What is going on here? Is it an ImageIcon problem, or are there others who have run into this. It has brought this project to a grinding halt, and I had thought this would be the easier part!!!! Please help me out gurus! Thanks!

    What options/values are you suggesting that I set? Or do you mean something else? Thank you for any ideas that can help me solve this problem. I never had any issues dealing with using ImageIcon for toolbar button graphics (file sizes of 1-3kb), but now with dealing with full page graphics I have run into a brick wall with this out of memory error.

  • Problem using a JTabbedPane in my application

    Hello, everybody.
    I am developping a application using the GUI editor NetBeans IDE 3.6 and I have some questions-problems.
    I encounter some problems with my JTabbedpane used in my application. I use a JTabbedPane with seven JPanel. On the first JPanel, I have some different components (JLabel, JComboBox, JTextField, JButton, List, ...) and it does not create any problem when I start my apllication.
    On the second JPanel of the JTabbedPane used, I separeted it with some other JPanel to differenciate the types of data's displayed in that tab and I also have a lot of different components on it ((JLabel, JComboBox, JTextField, JButton, List, ...).
    My first problem is that, when I start my application, the List component on the second Jpanel of my JTabbedPane appears above all the other tabs of my JTabbedPane until I click on the tab that contains that List. Once I have clicked on the second JPanel (that contains the List that makes me some problems), everythings becomes OK and it does not appear anymore above the other tabs (JPanel) of my JTabbedPane. I thing that it is a question a properties wrongly set, but I don't know the one I have to correct to eliminate that probem.
    The second problem is how to go from one JPanel (tab) to another JPanel (tab)with programming ??? For example, I would like to go to the second JPanel (tab) while double-clicking on a record present in a List in the first JPanel(tab). How can I do that ???
    A great thank you in advance for your help.
    Christian.

    For the seconds question, use the method setSelectedIndex() or setSelectedComponent(), whichever is more appropriate.
    The first problem I have also seen sometimes with tabbed panes. Can't remember how I corrected it though. Guess you could make sure the panels backgrounds are set to be opaque.

  • JLabel/JTextArea? which do i use and how

    When pressing a random button i need it to display a value, 1 line of text within a label or text area, when i press another button that represents another value i need it to display this value in the same label/text area but on a new line underneath this? I have read the API and can't see anything that shows how to do this?

    I am having problems with the text area. when i press
    a button it displays the text on the top line next to
    each other and carries on out of the text area, not
    strating a new line
    When i press a button 1 i want it to display "name"
    on the top line of the text area and when i press
    button 2 i want it to display "surname" underneath
    name. also for the text to be aligned to the left
    each time it starts on a new line. i am not sure how
    to go about coding thisIn that case, I'd just use two JLabels, one for each String. You can lay them out so they're aligned vertically, and left-aligned. If you're not sure how to lay them out that way, google "java layout tutorial"

  • JLabel ImageIcon not opaque.

    Hi I am having a little problem with my program that I am trying to develop.
    I have created a JFrame and instead of having the background the usual grey I have used an image.
    I then wanted to create some nice big buttons with nice smooth curved edges but was having trouble using the JButton so decicded to use a JLabel and attach a MouseListener to it. This seems to be working fine at the mo.
    The only problem is that instead of my nice gradient filled background being displayed I get a big white border around the JLabel. The rest of the background is perfectly displayed having only a problem around the JLabel. I have tried not using a background image and it shows the JLabel correctly and the button looks nice and smooth.
    I think it might be something to do with the rendering sequence maybe but I am at a loss. If any one has any ideas on how to fix it or a better way of doing it I would be most grateful.
    Many thanks for your help in advance.
    Matt
    PS now heres my code:
    public class GUI extends JFrame implements MouseListener {
         ImageIcon icon;
         JPanel buttonPanel = new JPanel();
         public GUI(){
              super("Property Works - Estate Agent Management System");
              icon = new ImageIcon("images/bg.jpg");
              JPanel panel = new JPanel(){
                   protected void paintComponent(Graphics g){
                        //g.drawImage(icon.getImage(), 0, 0, null);
                        Dimension d = getSize();
                        //g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);                    
                        super.paintComponent(g);                    
              panel.setOpaque(false);
              addButton();
              panel.add(buttonPanel);
              getContentPane().add(panel);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setExtendedState(JFrame.MAXIMIZED_BOTH);
              setVisible(true);
         public void addButton(){
              ImageIcon icon1 = new ImageIcon("images/buttons/addProperty.gif");
              JLabel addProperty = new JLabel(icon1);
              addProperty.setOpaque(false);
              addProperty.setToolTipText("Add a new property");
              addProperty.addMouseListener(this);
              JLabel tester = new JLabel("Tester");
              tester.setOpaque(false);
              buttonPanel.add(addProperty);
              buttonPanel.add(tester);     
         public void mousePressed(MouseEvent arg0) {
              // TODO Auto-generated method stub
              System.out.println("Button Clicked");
    }

    Swing related questions should be posted in the Swing forum.
    Use the "code" tags when you post code so the formatting is retained.
    The code you posted doesn't compile so we can't see the incorrect behaviour.
    Using code I already have I do not see any white border around the image. I tested using a "Duke" image which is found in many of the Swing tutorial examples. Maybe your image is the problem.

  • Need help in displaying an Image in a JLabel

    Hi everyone,
    I am using a JLabel to display images on a particular screen. I am facing some problem while doing so..
    On my screen there are images of some garments. When the users select colors from a particular list, i should color this garment images and load it on the screen again with the colors. I have a floodfill class for filling the colors in the images. The problem I am facing is I am able to color the image properly with my floodfill class but when displaying the image on the same jlabel, the image gets distorted somehow.
    Everytime I color the image, I create an ImageIcon of the image and use the seticon method from the JLabel class. First I set the icon to null and then set it to the imageicon created. here is the code I use.
    If 'image' is the the image i have to load
    ImageIcon imgicon = new ImageIcon(image);
    jlabel.setIcon(null);
    jlabel.setIcon(imgicon);I am setting the icon to null because I have not found any other method to clear the previous image from the jlabel.
    Can anyone who has worked on images before and faced a similar situation help me with this?? Is there some other container I can use besides the JLabel to display the images perhaps?
    Thanks in advance.....
    Bharat

    And the thing is when I first go into that screen with the selected colors it is displaying the images perfectly.
    It is only giving problems when I pick different colors on the screenit really sounds like the problem is in your floodfill class.
    I have no idea what's in floodfill, but if you were e.g. using a JPanel and paintComponent,
    you would need to have as the first line in paintComponent()
    super.paintComponent(..);
    to clear the previous painting.
    if not, you would be just drawing over the top of the previous paintComponent(), and if the calculation of the
    painting area is not 100% exact, you may get the odd pixel not painted-over, meaning those pixels will display
    the old color.

  • Why Chinese characters not showing up in JLabel correctly , sometimes ?

    I have a large program which uses a JLabel to display some Chinese characters in html, it was doing fine until the program grew larger and larger, then only html fonts in certain sizes will show up correctly, other sizes of the same fonts will show up as rectangles. It's not because it doesn't have these fonts, but it seems to be related to the complexity of the program. If I change the characters in rectangles to a different size ( smaller or larger ), they might show up correctly again (in the large program).
    I have a small test program below to see if a particular font size would show up correctly, they all showed up fine in this test, but if I try to display the same html in my large program, some sizes of characters will go wrong. I've even printed out the unicode and looked at them (6309 4f60 7684 9700 8981 ...), they are definitely in the Chinese character range.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Java_Test extends JPanel
      static int Total=900;
      JComboBox ComboBox_Array[]=new JComboBox[Total];
      Font Times_New_Roman_15_Font=new Font("Times New Roman",0,15);
      static int Small_Chinese_Font_Size=3;
      static String Software_Info_Chinese_Text="<Html><Table Width=100% Border=0 Cellpadding=2 Cellspacing=3><Tr><Td Align=Center><Font Size=6 Color=#3737FF>[ \u4EA7\u54C1\u7BA1\u7406 ] </Font></Td></Tr>"+
                                               "<Tr><Td Align=Center><Font Size=5 Color=green>\u5E2E\u52A9\u4F60\u7BA1\u7406\u4EA7\u54C1, \u5408\u540C, \u53CA\u5176\u5B83\u4FE1\u606F :</Font></Td></Tr>"+
                                               "<Tr><Td>\u8F93\u5165<Font Size="+Small_Chinese_Font_Size+" Color=#2255BB>"+
                                                 "<li>\u8F93\u5165, \u7EF4\u62A4\u548C\u6253\u5370\u8BE6\u7EC6\u4EA7\u54C1\u53CA\u4F9B\u8D27\u5546\u4FE1\u606F<Br>"+
                                                 "<li>\u5730\u5740\u548C\u5907\u6CE8\u4FE1\u606F\u53EF\u7528\u591A\u79CD\u8BED\u8A00\u8F93\u5165<Br>"+
                                               "</Font></Td></Tr>"+
                                               "</Table></Html>";
      JPanel Main_Panel=new JPanel();
      static boolean Exit_When_Window_Closed=false;
      Java_Test(String Test_String)
        for (int i=0;i<Total;i++) ComboBox_Array=new JComboBox();
    JLabel A_Non_English_Label=new JLabel(Test_String);
    A_Non_English_Label.setFont(Times_New_Roman_15_Font);
    A_Non_English_Label.setForeground(Color.BLUE);
    add(A_Non_English_Label);
    setPreferredSize(new Dimension(600,300));
    void Show_Up()
    Main_Panel.add(this);
    Dimension Screen_Size=Toolkit.getDefaultToolkit().getScreenSize();
    final JFrame frame=new JFrame("Java Test");
    frame.add(Main_Panel);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e) { if (Exit_When_Window_Closed) System.exit(0); }
    public void windowDeiconified(WindowEvent e) { Main_Panel.repaint(); }
    public void windowGainedFocus(WindowEvent e) { Main_Panel.repaint(); }
    public void windowOpening(WindowEvent e) { Main_Panel.repaint(); }
    public void windowResized(WindowEvent e) { Main_Panel.repaint(); }
    public void windowStateChanged(WindowEvent e) { Main_Panel.repaint(); }
    frame.pack();
    frame.setBounds((Screen_Size.width-Main_Panel.getWidth())/2,(Screen_Size.height-Main_Panel.getHeight())/2-10,Main_Panel.getWidth(),Main_Panel.getHeight()+50);
    frame.setVisible(true);
    Main_Panel.updateUI();
    static void Out(String message) { System.out.println(message); }
    public static void main(String[] args)
    Exit_When_Window_Closed=true;
    new Java_Test(Software_Info_Chinese_Text).Show_Up();
    final Java_Test demo=new Java_Test(Software_Info_Chinese_Text);
    Dimension Screen_Size=Toolkit.getDefaultToolkit().getScreenSize();
    final JFrame frame=new JFrame("Java Test");
    frame.add(demo);
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e) { System.exit(0); }
    public void windowDeiconified(WindowEvent e) { demo.repaint(); }
    public void windowGainedFocus(WindowEvent e) { demo.repaint(); }
    public void windowOpening(WindowEvent e) { demo.repaint(); }
    public void windowResized(WindowEvent e) { demo.repaint(); }
    public void windowStateChanged(WindowEvent e) { demo.repaint(); }
    frame.pack();
    frame.setBounds((Screen_Size.width-demo.getWidth())/2,(Screen_Size.height-demo.getHeight())/2-10,demo.getWidth(),demo.getHeight()+38);
    frame.setVisible(true);
    I called this test program from my large program, and it won't display correctly, it will only display all sizes of characters correctly if I run the test program by itself.
    I've posted a similar question in Java/Swing but got no answer. So I'm trying it here. The above test program will compile and run, it can display all sizes of html fonts correctly.Which means it's not lacking any fonts. I've even tried the following in my large program :
    dialog.validate();
    dialog.repaint();
    pane.validate();
    pane.repaint();
    pane.updateUI();
    A_Label.validate();
    A_Label.repaint();
    A_Label.updateUI();
    Still doesn't work, does anyone know why and how to fix it ?
    Frank                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I've just made a breakthrough, the large program will work correctly if I comment out : A_Non_English_Label.setFont(Times_New_Roman_15_Font);
    But then the font doesn't look the way I wanted it to be.
    So I changed it to the following :
    ================================================
    Font Courier_New_15_Font=new Font("Courier New",0,15);
    A_Non_English_Label.setFont(Courier_New_15_Font);
    ================================================
    Now it looks not the same but similar to the way I wanted. Thus my question becomes : why it can't work correctly with "Times_New_Roman", but with "Courier_New" in the large program, they both displayed correctly in my small test program ? Is it because it takes too much resource to load the "Times_New_Roman" font ?
    Frank

  • Using animation as icon for JTree node

    Hi,
    I am using a custom tree cell renderer. I have a label in the renderer, the label have gif Image Icon, but the problem is it is not getting animated. But when I use a JLabel with gif icon some where else it is working fine, but it is not working for tree node.
    package com.gopi.utilities.gui;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeCellRenderer;
    import com.gopi.remfilebrowser.gui.GUIUtil;
    import com.gopi.remfilebrowser.util.FileBrowserConstants;
    public class CustomTreeCellRenderer implements TreeCellRenderer
         private JPanel panel;
         private JLabel label;
         private TreeCellRenderer defaultRenderer;
         public CustomTreeCellRenderer()
              super();
              panel = GUIUtil.createGridBagPanel();
              label = new JLabel();
              label.setHorizontalAlignment(JLabel.LEFT);
              System.out.println("New");
              GridBagConstraints gc = new GridBagConstraints();
              GUIUtil.fillComponent(panel,label);
              defaultRenderer = new DefaultTreeCellRenderer();
         public Component getTreeCellRendererComponent(JTree tree, Object value,
                     boolean sel,
                     boolean expanded,
                     boolean leaf, int row,
                     boolean hasFocus)
              if(value instanceof NewAbstractTreeNode)
                   NewAbstractTreeNode node = (NewAbstractTreeNode) value;
                   System.out.println("dr");
                   label.setText(value.toString());
                   label.setIcon(ImageLoader.getInstance().getIcon(node.getIconKey()));
                   if(hasFocus && sel)
                        panel.setBackground(FileBrowserConstants.TREE_NODE_SELECTED_COLOR);
                   else if(sel)
                        panel.setBackground(FileBrowserConstants.TREE_NODE_UNSELECTED_COLOR);
                   else
                        panel.setBackground(Color.white);
                   return panel;
              return defaultRenderer.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
    }

    JLabels using ImageIcons are designed to display the icon as is, including animation and all.
    A CellRenderer only paints the Icon once, when the cell is painted. Much ike a rubber stamp of the JComponent. Hence, its not designed to do the animation and all.
    If you really want it, you can probably use MediaTracker and a Timer to do your animation scheduling. Might not be very pretty code though
    ICE

  • How to bring the hyperlink in a JLabel object ?

    How to bring the hyperlink in a JLabel object ?
    I tried the following--> [ this is a sample ]
    JLabel label;
    label=new JLabel("<HTML><A HREF='file://D:/Examination/calc.exe'>Calculator</A></HTML>");Using this JLabel object in an JDialog the label comes perfectly with such a look of the hyperlink
    [ Blue coloured and underlined ] that's all !!
    It doesn't work anything that it should do.
    While all the html tags work perfectly in java then why the hyperlink in label doesn't ?
    If you have an idea then please send me the code.
    Thanks!

    see JXHyperLink at https://swingx.dev.java.net/
    Yeah, I looked at this. I agree with the other guy who said that all this does, presumably, is change the color of the text when the button is getting mousedover. That doesn't solve anything.
    As far as JEditorPane, it has its bad points and ... well, mostly bad points. However that's not really fair. JEditorPane was not designed to be on the level of an IE or FireFox.
    The BEST thing to use JEditor's web browsing facilities on is for creating your own documentation and help pages for software you are developing. Here is a list of some of the things JEditorPane does not come equiped with (as of 1.4 I haven't tried playing with it in 1.5):
    1. Form submission, PUT, and GET
    2. Download status
    3. Caching
    4. Cookies
    5. Plugins (ie Java, Flash, Quicktime)
    6. No javascript.
    Beyond that it is extremely brittle in parsing the HTML, and if the HTML is not totally well formed (and many pages are not) you won't get anything

  • Layout problem with JTabbedPane

    Hi,
    I'm creating a JDialog with a JOptionPane in it which has a JTabbedPane as its ContentPane
    Supposed to look like the pic below. I've put the JOptionPane into a JScrollPane in case the user makes the Dialog too small.
    Problem is that the JTabbedPane stretches to a very large height (way bigger than the dialog height).
    Using setPreferredSIze(..) on the JTabbedPane doesn't help either. If the dialog is made bigger, then the TAbbedPane doesn't stretch, if it is made smaller, the TabbedPane shrinks to the minimum necessary size.
    Any ideas, tips on getting this layout would be appreciated.
    |                                      |/\|
    |  ----- -----                         |--|
    |  |   | |   |                         |  |
    | -----------------------------------  |  |
    | |                                 |  |  |
    | |  2 Tables and several buttons   |  |__|
    | |  on this JTabbedPane using      |  |  |
    | |  GridBagLayout                  |  |__|
    | |                                 |  |  |
    | -----------------------------------  |  |
    |                                      |  |
    |          | OK | | Cancel |           |--|
    |                                      |\/|
    -------------------------------------------

    Check this: http://forum.java.sun.com/thread.jsp?forum=57&thread=293587
    - ananth
    Hi,
    I'm creating a JDialog with a JOptionPane in it which
    has a JTabbedPane as its ContentPane
    Supposed to look like the pic below. I've put the
    JOptionPane into a JScrollPane in case the user makes
    the Dialog too small.
    Problem is that the JTabbedPane stretches to a very
    large height (way bigger than the dialog height).
    Using setPreferredSIze(..) on the JTabbedPane doesn't
    help either. If the dialog is made bigger, then the
    TAbbedPane doesn't stretch, if it is made smaller, the
    TabbedPane shrinks to the minimum necessary size.
    Any ideas, tips on getting this layout would be
    appreciated.
    |                                      |/\|
    |  ----- -----                         |--|
    |  |   | |   |                         |  |
    | -----------------------------------  |  |
    | |                                 |  |  |
    | |  2 Tables and several buttons   |  |__|
    | |  on this JTabbedPane using      |  |  |
    | |  GridBagLayout                  |  |__|
    | |                                 |  |  |
    | -----------------------------------  |  |
    |                                      |  |
    |          | OK | | Cancel |           |--|
    |                                      |\/|

  • How to scroll at the bottom using scroll pane

    i am having a label in which i have added a scroll pane. dynamically i will add some text to the label. the scroll bar should move to the buttom after addition of text so that the new text added should be visible.
    please provide me a solution.

    Swap from using a JLabel to a JTextArea, then use below to set position viewed. (do this after each time you enter any text)
    yourJTextArea.setCaretPosition(yourJTextArea.getText().length());

  • Html text in label is moving when used as a renderer in a table cell

    Hi everybody,
    Because it is impossible to use gradient background for html, I created a custom TableCellRenderer that uses a JLabel (for the html text) inside a JPanel with a gradient background. (I use jdk1.5.0_06)
    However, in the code that I'm posting, something strange happens. The text is moving up and down as I move with the arrow button along the first row, from left to right and backwards, crossing the entire row.
    You can see for yourself. If someone can explain this behavior, please help!
    public class MyFrame extends javax.swing.JFrame {
        public static void main(String args[]) {
               new MyFrame().setVisible(true);
        public MyFrame() {
             setTitle("Use LEFT & RIGHT buttons to test");
            javax.swing.JTable table = new javax.swing.JTable();
            table.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] { {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""} },
                new String []   { "Title 1", "Title 2", "Title 3" }
                public Class getColumnClass(int columnIndex) {
                    return String.class;
            table.setRowHeight(30);
            table.setRowHeight(0,100);
            table.setRowSelectionInterval(0,0);
            table.setColumnSelectionInterval(0,0);
            table.setValueAt("This text MOVES up-down as you move across THIS ROW!!!",0,0);
            table.setValueAt("This text MOVES up-down as you move across THIS ROW!!!",0,1);
            table.setValueAt("This text DOES NOT MOVE as you move across THIS ROW!!!",0,2);
            table.setDefaultRenderer(String.class,new StringRenderer());
            getContentPane().add(table, java.awt.BorderLayout.CENTER);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setBounds(200,200,500,300);
        class StringRenderer extends GradientPanel implements javax.swing.table.TableCellRenderer {
            public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                   label.setText("<html><p align=center>"+String.valueOf(value)+"</p></html>");
                setColors(new java.awt.Color(255,255,255),isSelected?new java.awt.Color(255,100,100):new java.awt.Color(255,200,200));
                label.setBorder(hasFocus?new javax.swing.border.LineBorder(java.awt.Color.yellow,1):null);
                return this;
        class GradientPanel extends javax.swing.JPanel {
            private java.awt.Color c1,c2;
            protected javax.swing.JLabel label;
            public GradientPanel() {
                label = new javax.swing.JLabel();
                setLayout(new java.awt.GridBagLayout());
                java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints();
                gbc.fill = java.awt.GridBagConstraints.BOTH;
                gbc.weightx = 1.0;
                gbc.weighty = 1.0;
                gbc.insets = new java.awt.Insets(5,5,5,5);
                add(label, gbc);
            public void setColors(java.awt.Color c1, java.awt.Color c2) {
                this.c1 = c1;
                this.c2 = c2;
                this.repaint();
            public void paintComponent(java.awt.Graphics g) {
                if ( c1 != null && c2 != null ) {
                    java.awt.Graphics2D g2d = (java.awt.Graphics2D)g;
                    g2d.setPaint(new java.awt.GradientPaint(0,0,c2,0,this.getHeight(),c1,false));
                    g2d.fillRect(0,0,this.getWidth(),this.getHeight());
    }

    If someone can explain this behavior, please help!Can't explaing the behavour, but it seems to work fine when you use a JeditorPane or JTextPane which are specifically designed to display HTML.

  • Unable to change the text of a JLabel

    hi!
    i have created a JLabel and add it to my frame. Now, when the user clicks the button on the frame, i changed the test of the label and after that some really heavy processing takes place. and till that processing completes, the changed text does not get display. is it because that the repaint has very low priority? my requirement is that the text shuld get updated immediately.
    Any ideas?
    regards
    Deepak Saini

    I usually suggest to use:
    component.paintImmediately(component.getVisibleRect());
    Wondering what the difference between 'paintImmediately()' and 'update()' was, I created a simple test program. The program simply changed the text in a JTextField 1000 times.
    Here is what I found:
    1) paintImmediately was 10-20% faster
    2) paintImmediately produced no flicker
    I changed my program to use a JLabel instead of a JTextField and found:
    1) update() did not work
    Here is my sample program in case you are interested.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    public class StatusBar extends JFrame
         JTextField statusBar;
    public StatusBar()
    JPanel panel = new JPanel();
    panel.setLayout( new BorderLayout() );
         setContentPane( panel );
              JButton button = new JButton( "Connect..." );
              panel.add( button, BorderLayout.NORTH );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
         long t1 = System.currentTimeMillis();
                        for (int i = 0; i < 1000; i++)
                             statusBar.setText( "label " + i );
    //                         statusBar.paintImmediately(statusBar.getVisibleRect());
                             statusBar.update(statusBar.getGraphics());
                        System.out.println( (System.currentTimeMillis() - t1) );
              statusBar = new JTextField("No Connection");
              panel.add( statusBar, BorderLayout.SOUTH );
    public static void main(String[] args)
    StatusBar frame = new StatusBar();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.pack();
    frame.setVisible(true);

Maybe you are looking for

  • Why am i not able to see all tabs in cs6

    Your Adobe ID:[email protected] Your Case Number:0185063109 Case Description:ccm installation

  • Losing objects when producing a pdf

    CS5, Mac, 10.5.8 I have a page with 5 photos and type, grayscale photos and spot color stroke around the photos. Inverse rounded photos. When I produce any type pdf with bevel and emboss added to the photos they disappear in the pdf. In InDesign tran

  • 10g DBA OCP requirements

    Dear All, please give me an advice in the following thread: Oracle 10g OCP DBA Hands-on Course ? (People having OCP certification can help for sure.) Thank You! Franky

  • Change Request Vs Change Order

    Hi, What is the difference between change request and change orders. When to use Change request and when to use Change order. Both allow impacts on work & financial plans Thanks Govind

  • Sale of Non stock material - material type(NLAG)

    Hi all, Is it possible to sell a non stock material which is maintained as a material master through material type NLAG. How to map this scenorio in SAP Kindly let me know regarding this. Regards Saru.