Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTabbedPane tabs not restored after a JDialog window is closed

61 views
Skip to first unread message

Tom Nott

unread,
Sep 13, 1999, 3:00:00 AM9/13/99
to
I'm using a JTabbedPane to perform main menu funcitonality. When one
of the JDialog sub-menu functions is performed and then closed, the tabs
on the JTabbedPane are no longer displayed. The text of the panel
assoicated with the selected JTabbedPane is present. The tabs do not
reshow until the user clicks the mouse over where the panes should be in
the window.
It appears that the focus is being transfered back to the
JTabbedPane, but where are the tabs? I've tried to repaint and paint,
but to no avail.
Thanks in advance for any assistance.

Tom Nott


G. S. Link

unread,
Sep 14, 1999, 3:00:00 AM9/14/99
to
That's a bug! Good luck trying to get it fixed, because it is in the
Swing code and IBM will point a finger at Sun. Sun will tell you that
the code is obsolete.


Mark McMillan

unread,
Sep 14, 1999, 3:00:00 AM9/14/99
to
Not sure if this is your problem, but try making all your tab panels
small (e.g. 10x10) before adding them to the tab control. There is a
Swing bug that prevent proper repaint of the tabs when one of the tab
panels was bigger than the tab control itself when it was added.

I had several back-and-forth e-mails with one of the Sun Swing
developers about it and could not convince him it was a bug. Here is
the text of my submission and the workaround description. Hope this
helps...

----------------------------------

description: The JTabbedPane fail to paint correctly if it contains a
JPanel
which is larger than the JTabbedPane itself. There are two
conditions that lead to this problem: (1) A page of the JTabbedPane
contains a component which is oversize, e.g. larger than the JTabbedPane
itself, and (2) the oversized component is NOT on the first tab.

Here is a short program which shows the problem. When run the
frame is shown with nothing inside it (the JTabbedPane does not
draw itself). The correct behaviour can be obtained by changing
either of the code blocks as indicated in the comments to either
(1) make the component smaller than the tab control, or (2) making
the oversized component the first tab.

import com.sun.java.swing.*;
import java.awt.*;

public class TabBug extends com.sun.java.swing.JFrame {

class TestPanel extends JPanel {
public TestPanel() {
super();
setName("TestPanel2");
setLayout(null);
setSize(500, 810); //<=== Tab fails to paint
//setSize(500, 200); //<=== Works correctly
}
}

public TabBug() {
super();
setName("TabTest");

setDefaultCloseOperation(com.sun.java.swing.WindowConstants.DISPOSE_ON_CLOSE);
setSize(485, 316);

// Create tabbed pane
JTabbedPane tab = new JTabbedPane();
tab.setBounds(20, 20, 250, 250);

// Fails when oversized panel is 2nd tab:
tab.insertTab("Page 1", null, new JPanel(), null, 0);
tab.insertTab("Page 2", null, new TestPanel(), null, 1);

// Works when oversized panel is 1st tab:
//tab.insertTab("Page 2", null, new TestPanel(), null, 0);
//tab.insertTab("Page 1", null, new JPanel(), null, 1);

JRootPane root = getRootPane();
root.setName("JFrameContentPane");
root.setLayout(null);
root.add(tab);

}
public TabBug(String title) {
super(title);
}
public static void main(java.lang.String[] args) {
TabBug b = new TabBug();
b.setVisible(true);
}
}

company: NCFB Insurance

jdcid: %%userid%%

comments: (company - NCFB Insurance , email - mmcm...@ncfbins.com)


cust_email: mmcm...@ncfbins.com

status: Waiting

workaround: Set the size of components to very small (10x10) before
inserting
them into the JTabbedPane. This may not be practical or possible
with some visual design environments where the tab insert code
is generated by an IDE.

OSversion: win_nt_4.0

severity: 3

dateCreated: July 20, 1999 7:59:36 AM

performance: 1

crash: 1

user_type: E

subcategory: classes_swing

bugtype: bug

hardware: x86

security: 1

cust_name: Mark McMillan

category: java

hang: 1

synopsis: JTabbedPane fail to paint with an oversized child on 2nd page

G. S. Link

unread,
Sep 15, 1999, 3:00:00 AM9/15/99
to
I hate to say it, but this sort of thing is going to sink Java. I had
the same problem and got the same result.


Tom Nott

unread,
Sep 15, 1999, 3:00:00 AM9/15/99
to
Mark,
Thanks for your response, but I think my problem is slightly different. I
don't have a problem with any of the JPanes that have been added to the
JTabbedPane initially. They all show up and work as expected. I did verify that
the JTabbedPane size is larger than all the JPanes that are in it, it was.
My problem is when I press a JButton to invoke a function from one of these
JTabbedPane owned JPanes (for instance connecting to DB2). Each of these
functions pops up a JDialog that then can perform additional stuff. Its when I
close one of these JDialogs that the tabs on the JTabbedPane disappear. If I
click on where these tabs should be they show up.
I'm basically a novice at Java, but it would appear that when the JTabbedPane
regains focus its not repainted properly. This might be an extension of the
problem you had.

Thanks

Tom

Mark McMillan

unread,
Sep 15, 1999, 3:00:00 AM9/15/99
to
As much as it fustrates me, I am not too sure about your conclusion.
You know how many Win32 bugs there are that Microsoft has deemed to be
'features' or 'WAD'? Every API vendor does this to some degree or
another; Swing is still quite new compared to other windowing APIs.

-Mark

Tom Nott

unread,
Sep 15, 1999, 3:00:00 AM9/15/99
to
To all,
Got around this problem by extrapolating what Mark said. By setting the size of
all the JDialog panels that are invoked from the JPanes added to the JTabbedPane to
be larger than the JTabbedPane, this appears to work.
I don't have a clue why.

Tom

0 new messages