JD3 vs JD2 - jTabbedPane bug?

In a JD3 applet, after placing several infobus components on each of several jTabbedPane jPanels, the applet runs in neither the appletviewer nor when deployed. However, when the applet is run in the appletviewer, it can be seen if you select the "restart" item in the pull-down menu of the appletviewer.
When the components are placed on only the first of the jPanels, the applet does run correctly in the appletviewer and also when deployed. However, if after placing components on more than one JPanel, you remove the components from all but the first jPanel, the problem persists.
The problem described above does not exist in JD2.

The following problem applies to JD3 but not JD2, where things work correctly.
The code below produces an applet with three tabs. Each tab has one or more components on it. If you drag and drop (reposition) the components on the second or third tab, the applet can neither be seen in the appletviewer nor deployed. You can reposition the components programatically, but this is impractical for the case where a few hundred components are involved.
Is there a way to drag and drop components on these tabs without "breaking" the application?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import oracle.jdeveloper.layout.*;
public class Applet1 extends JApplet {
boolean isStandalone = false;
JPanel jPanel1 = new JPanel();
JTabbedPane jTabbedPane1 = new JTabbedPane();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
//Construct the applet
public Applet1() {
//Initialize the applet
public void init() {
try {
jbInit();
catch (Exception e) {
e.printStackTrace();
//Component initialization
private void jbInit() throws Exception {
this.setSize(400,300);
jPanel1.setLayout(null);
jTabbedPane1.setBounds(new Rectangle(49, 5, 303, 274));
jPanel4.setLayout(xYLayout1);
jPanel3.setLayout(xYLayout1);
jPanel2.setLayout(xYLayout1);
jButton1.setText("jButton1");
jButton2.setText("jButton2");
jButton3.setText("jButton3");
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jTabbedPane1, null);
jTabbedPane1.addTab("Pane 0", jPanel4);
jPanel4.add(jButton3,new XYConstraints(126, 57, -1, -1));
jPanel4.add(jTextField1, new XYConstraints(73, 143, 102, 23));
jTabbedPane1.addTab("Pane 1", jPanel3);
jPanel3.add(jButton1, new XYConstraints(126, 57, -1, -1));
jPanel3.add(jTextField2,new XYConstraints(59, 140, 90, 23));
jTabbedPane1.addTab("Pane 2", jPanel2);
jPanel2.add(jButton2, new XYConstraints(126, 57, -1, -1));
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
//Get parameter info
public String[][] getParameterInfo() {
return null;
null

Similar Messages

  • Tab of JTabbedPane bug perhaps?

    I've noticed many instances of JTabbedPane not setting current selected
    tabs to a specified color. I find this kind of strange since it seems
    like it's the other way around on my Solaris as well as my HP-UX box.
    What I'm wondering is if this is a new bug that got introduced by an
    attempt to "fix" the original bug where the selected tab is not taking
    the new color? If so, what's the workaround to getting the unselected
    tabs to respect the new color that one wishes to invoke?
    I've tried a myriad of techniques to get this unselected tab color to
    change to the color I wished for it to be, but to my dismay it always
    stay a Color.darkGray color. I was successful in changing the background
    of the selected, but not the unselected tabs.
    I've used UIManager and my own customized LookAndFeel manipulator to
    get the other stuff to work, except for this annoying "bug" it seems.
    Please help..
    Thanks in advance..

    Well.. I've been doing that and nothing seems to budge..
    Not sure exactly why it seems like whatever is done whether
    it be through the custom L&F or through custom subclass of
    JTabbedPane that forcibly/manually alter the color properties,
    nothing happens.
    So, to me, it just feels like an internal JVM bug.

  • Bug: JTabbedPane setTabLayoutPolicy in 1.4

    I noticed weird behavior when using setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT). When adding a MouseListener to a JTabbedPane with this property set (it's a recent addition since 1.4), mouseClicked, mouseReleased, and mousePressed events do not occur. These events don't occur when clicked on the tab name (it works in other various areas though), but this is not standard behavior. When adding a MouseListener to a JTabbedPane, these events should occur no matter where you clicked on the JTabbedPane. Expected results are received with the default value, setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT). Here's someone else (the only other person I know) who experienced this problem:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=185937
    Try running his code (my code is too long to show, it's part of a big project) and let me know if this bug exists for whatever operating system you use. Could anyone let me know if there's a workaround for this problem? I filed this bug and I hope Sun will fix it soon :) Thanks.

    I dunno whether its a bug or not but in my old application Tab key stopped working when run on JRE1.4.1!
    And if I had Java Console open Tab worked fine (earlier we were using JRE1.3 plugin, now I tried the application on JRE1.4.1 ).
    Only after setting the myApplet.FocusCycleRoot(true) did it started working again.
    Cheers,
    Amit

  • JD3 1.2.2 VM RMI Bug

    Hi
    I think there is another problem with the 1.2.2 VM.
    This is the simplest RMI Java program and it does not work on
    the JDeveloper3 1.2.2 VM
    this program work with no problems on the Jbuilder3 VM and Sun VM
    Also the error is reported when executing Naming.rebind the
    problem is probebly in LocateRegistry.createRegistry as if some
    other VM already created the registry the program will
    work correctly both at JD VM and other VM.
    JDeveloper 3
    VM 1.2.2
    NT 4 SP4
    Regards,
    Muly.
    ***************************** RemoteInterface.java
    package test.rmiTest;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface RemoteInterface extends Remote {
    public void sample() throws RemoteException;
    ***************************** RemoteInterfaceImpl.java
    package test.rmiTest;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public class RemoteInterfaceImpl extends UnicastRemoteObject
    implements RemoteInterface {
    public RemoteInterfaceImpl() throws RemoteException {
    super();
    public void sample() throws RemoteException {
    System.out.println("Ok");
    ***************************** MainClass.java
    package test.rmiTest;
    import java.rmi.RemoteException;
    import java.rmi.RMISecurityManager;
    import java.rmi.Naming;
    import java.rmi.NotBoundException;
    import java.net.MalformedURLException;
    import java.rmi.registry.LocateRegistry;
    public class MainClass extends Object {
    public MainClass() throws Exception {
    RemoteInterface ri = new RemoteInterfaceImpl();
    String logUrl = "rmi://localhost:1099";
    int index = logUrl.lastIndexOf(":");
    String portString = logUrl.substring(index + 1).trim();
    int port = Integer.parseInt(portString);
    try {
    LocateRegistry.createRegistry(port);
    System.out.println("rmiregistry created on port " + port);
    } catch (Exception ex) {
    System.out.println("assuming existing rmiregistry on
    port " + port);
    Naming.rebind("sample", ri);
    System.out.println("Ok");
    System.exit(0);
    public static void main(String[] args) {
    try {
    MainClass mainClass = new MainClass();
    } catch (Exception e) {
    System.out.println(e);
    ***************************** error message from JD3 VM
    rmiregistry created on port 1099
    java.rmi.ServerException: RemoteException occurred in server
    thread; nested exce
    ption is:
    java.rmi.UnmarshalException: error unmarshalling
    arguments; nested excep
    tion is:
    java.lang.ClassNotFoundException:
    test.rmiTest.RemoteInterfaceImpl_Stub
    ***************************** Correct output from other VM
    rmiregistry created on port 1099
    Ok
    null

    Muly,
    Confirmed. This is reproducable. One of our developers is
    looking into it.
    Laura
    Muly (guest) wrote:
    : Hi
    : I think there is another problem with the 1.2.2 VM.
    : This is the simplest RMI Java program and it does not work on
    : the JDeveloper3 1.2.2 VM
    : this program work with no problems on the Jbuilder3 VM and Sun
    VM
    : Also the error is reported when executing Naming.rebind the
    : problem is probebly in LocateRegistry.createRegistry as if some
    : other VM already created the registry the program will
    : work correctly both at JD VM and other VM.
    : JDeveloper 3
    : VM 1.2.2
    : NT 4 SP4
    : Regards,
    : Muly.
    : ***************************** RemoteInterface.java
    : package test.rmiTest;
    : import java.rmi.Remote;
    : import java.rmi.RemoteException;
    : public interface RemoteInterface extends Remote {
    : public void sample() throws RemoteException;
    : ***************************** RemoteInterfaceImpl.java
    : package test.rmiTest;
    : import java.rmi.server.UnicastRemoteObject;
    : import java.rmi.Remote;
    : import java.rmi.RemoteException;
    : public class RemoteInterfaceImpl extends UnicastRemoteObject
    : implements RemoteInterface {
    : public RemoteInterfaceImpl() throws RemoteException {
    : super();
    : public void sample() throws RemoteException {
    : System.out.println("Ok");
    : ***************************** MainClass.java
    : package test.rmiTest;
    : import java.rmi.RemoteException;
    : import java.rmi.RMISecurityManager;
    : import java.rmi.Naming;
    : import java.rmi.NotBoundException;
    : import java.net.MalformedURLException;
    : import java.rmi.registry.LocateRegistry;
    : public class MainClass extends Object {
    : public MainClass() throws Exception {
    : RemoteInterface ri = new RemoteInterfaceImpl();
    : String logUrl = "rmi://localhost:1099";
    : int index = logUrl.lastIndexOf(":");
    : String portString = logUrl.substring(index + 1).trim();
    : int port = Integer.parseInt(portString);
    : try {
    : LocateRegistry.createRegistry(port);
    : System.out.println("rmiregistry created on port " +
    port);
    : } catch (Exception ex) {
    : System.out.println("assuming existing rmiregistry on
    : port " + port);
    : Naming.rebind("sample", ri);
    : System.out.println("Ok");
    : System.exit(0);
    : public static void main(String[] args) {
    : try {
    : MainClass mainClass = new MainClass();
    : } catch (Exception e) {
    : System.out.println(e);
    : ***************************** error message from JD3 VM
    : rmiregistry created on port 1099
    : java.rmi.ServerException: RemoteException occurred in server
    : thread; nested exce
    : ption is:
    : java.rmi.UnmarshalException: error unmarshalling
    : arguments; nested excep
    : tion is:
    : java.lang.ClassNotFoundException:
    : test.rmiTest.RemoteInterfaceImpl_Stub
    : ***************************** Correct output from other VM
    : rmiregistry created on port 1099
    : Ok
    null

  • How can we prevent JTabbedPanes from transferring focus to components outside of the tabs during tab traversal?

    Hi,
    I noticed a strange focus traversal behavior of JTabbedPane.
    During tab traversal (when the user's intention is just to switch between tabs), the focus is transferred to a component outside of the tabs (if there is a component after/below the JTabbedPane component), if using Java 6. For example, if using the SSCCE below...
    import java.awt.BorderLayout;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class TabbedPaneTest extends JPanel {
        public TabbedPaneTest() {
            super(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents());
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            add(new JScrollPane(panel));
        private JPanel buildPanelWithChildComponents() {
            JPanel panel = new JPanel();
            BoxLayout boxlayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
            panel.setLayout(boxlayout);
            panel.add(Box.createVerticalStrut(3));
            for (int i = 0; i < 4; i++) {
                panel.add(new JTextField(10));
                panel.add(Box.createVerticalStrut(3));
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneTest());
                    frame.pack();
                    frame.setVisible(true);
    ... Then we can replicate this behavior by following these steps:
    1) Run the program in Java 6; and then
    2) Click on a child component in any of the tabs; and then
    3) Click on any other tab (or use the mnemonic keys 'ALT + 1' to 'ALT + 4').
    At step 3 (upon selecting any other tab), the focus would go to the component below the JTabbedPane first (hence the printed message in the console), before actually going to the selected tab.
    This does not occur in Java 7, so I'm assuming it is a bug that is fixed. And I know that Oracle suggests that we should use Java 7 nowadays.
    The problem is: We need to stick to Java 6 for a certain application. So I'm looking for a way to fix this issue for all our JTabbedPane components while using Java 6.
    So, is there a way to prevent JTabbedPanes from passing the focus to components outside of the tabs during tab traversal (e.g. when users are just switching between tabs), in Java 6?
    Note: I've read the release notes between Java 6u45 to Java 7u15, but I was unable to find any changes related to the JTabbedPane component. So any pointers on this would be deeply appreciated.
    Regards,
    James

    Hi Kleopatra,
    Thanks for the reply.
    Please allow me to clarify first: Actually the problem is not that the child components (inside tabs) get focused before the selected tab. The problem is: the component outside of the tabs gets focused before the selected tab. For example, the JButton in the SSCCE posted above gets focused when users switch between tabs, despite the fact that the JButton is not a child component of the JTabbedPane.
    It is important for me to prevent this behavior because it causes a usability issue for forms with 'auto-scrolling' features.
    What I mean by 'auto-scrolling' here is: a feature where the form automatically scrolls down to show the current focused component (if the component is not already visible). This is a usability improvement for long forms with scroll bars (which saves the users' effort of manually scrolling down just to see the focused component).
    To see this feature in action, please run the SSCCE below, and keep pressing the 'Tab' key (the scroll pane will follow the focused component automatically):
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextField;
    import javax.swing.JViewport;
    import javax.swing.SwingUtilities;
    public class TabbedPaneAutoScrollTest extends JPanel {
        private AutoScrollFocusHandler autoScrollFocusHandler;
        public TabbedPaneAutoScrollTest() {
            super(new BorderLayout());
            autoScrollFocusHandler = new AutoScrollFocusHandler();
            JTabbedPane tabbedPane = new JTabbedPane();
            tabbedPane.addTab("Tab 1", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
            tabbedPane.addTab("Tab 2", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
            tabbedPane.addTab("Tab 3", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
            tabbedPane.addTab("Tab 4", buildPanelWithChildComponents(20));
            tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(tabbedPane);
            JButton button = new JButton("Dummy component that gains focus when switching tabs");
            panel.add(button, BorderLayout.SOUTH);
             * To replicate the focus traversal issue, please follow these steps -
             * 1) Run this program in Java 6; and then
             * 2) Click on a child component inside any tab; and then
             * 3) Click on any other tab (or use the mnemonic keys ALT + 1 to ALT 4).
            button.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    System.err.println("Gained focus (not supposed to when just switching tabs).");
            button.addFocusListener(autoScrollFocusHandler);
            JScrollPane scrollPane = new JScrollPane(panel);
            add(scrollPane);
            autoScrollFocusHandler.setScrollPane(scrollPane);
        private JPanel buildPanelWithChildComponents(int numberOfChildComponents) {
            final JPanel panel = new JPanel(new GridBagLayout());
            final String labelPrefix = "Dummy Field ";
            final Insets labelInsets = new Insets(5, 5, 5, 5);
            final Insets textFieldInsets = new Insets(5, 0, 5, 0);
            final GridBagConstraints gridBagConstraints = new GridBagConstraints();
            JTextField textField;
            for (int i = 0; i < numberOfChildComponents; i++) {
                gridBagConstraints.insets = labelInsets;
                gridBagConstraints.gridx = 1;
                gridBagConstraints.gridy = i;
                panel.add(new JLabel(labelPrefix + (i + 1)), gridBagConstraints);
                gridBagConstraints.insets = textFieldInsets;
                gridBagConstraints.gridx = 2;
                textField = new JTextField(22);
                panel.add(textField, gridBagConstraints);
                textField.addFocusListener(autoScrollFocusHandler);
            return panel;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test for Java 6 with auto-scrolling");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneAutoScrollTest());
                    frame.setSize(400, 300);
                    frame.setVisible(true);
    * Crude but simple example for auto-scrolling to focused components.
    * Note: We don't actually use FocusListeners for this feature,
    *       but this is short enough to demonstrate how it behaves.
    class AutoScrollFocusHandler extends FocusAdapter {
        private JViewport viewport;
        private JComponent view;
        public void setScrollPane(JScrollPane scrollPane) {
            viewport = scrollPane.getViewport();
            view = (JComponent) viewport.getView();
        @Override
        public void focusGained(FocusEvent event) {
            Component component = (Component) event.getSource();
            view.scrollRectToVisible(SwingUtilities.convertRectangle(component.getParent(),
                    component.getBounds(), view));
    Now, while the focus is still within the tab contents, try to switch to any other tab (e.g. by clicking on the tab headers, or by using the mnemonic keys 'ALT + 1' to 'ALT + 4')...
    ... then you'll notice the following usability issue:
    1) JRE 1.6 causes the focus to transfer to the JButton (which is outside of the tabs entirely) first; then
    2) In response to the JButton gaining focus, the 'auto-scrolling' feature scrolls down to the bottom of the form, to show the JButton. At this point, the tab headers are hidden from view since there are many child components; then
    3) JRE 1.6 transfers the focus to the tab contents; then
    4) The 'auto-scrolling' feature scrolls up to the selected tab's contents, but the tab header itself is still hidden from view (as a side effect of the behavior above); then
    5) Users are forced to manually scroll up to see the tab headers whenever they are just switching between tabs.
    In short, the tab headers will be hidden when users switch tabs, due to the Java 6 behavior posted above.
    That is why it is important for me to prevent the behavior in my first post above (so that it won't cause usability issues when we apply the 'auto-scrolling' feature to our forms).
    Best Regards,
    James

  • Loss of functionality in JD3?

    In a JD3 applet, the ComboBoxControl** will update a row (such as empno = 100) in the EMP table that already has a JOB value (e.g., 'Clerk'). However, the ComboBoxControl will NOT update a row (such as empno = 125) in the EMP table that DOES NOT already have a JOB value.
    When the same scenario is tried in JD2, the ComboBoxControl will update the JOB value whether or not the selected row already has a JOB value.
    IS THE JD2 FUNCTIONALITY DESCRIBED ABOVE AVAILABLE IN JD3? IF SO, HOW?
    Marcia
    ** An array of strings is used in the Constructor of the ComboBoxControl. The ComboBoxControl is "bound" to the JOB column (attribute).

    I have had the same concern.

  • Keyboard shortcuts in JTabbedPane don't work in BorderLayout

    I'm mystified by a problem that doesn't seem to make any sense. I have a JTabbedPane with mnemonics, that used to work well before. But since I've shuffled components around a bit and put the JTabbedPane in the BorderLayout.CENTER of a JPanel, the keyboard shortcuts no longer work.
    The appropriate letters are underlined, but the Alt+letter sequence no longer switched tabs. Other components (JButtons) with keyboard shortcuts in the same JPanel, but in the BorderLayout.SOUTH or elsewhere, work as expected.
    It sounds like a bug to me, but is there perhaps a workaround?
    Thanks,
    - Peter

    I keep replying to my own posts...
    I figured out that the tabs start working once a component in them (say, a JTextField) receives keyboard focus. It does sound a bit suspicious to me, but I can live with it.
    Unfortunately, setting the focus programmatically doesn't seem to work: requestFocus() or requestFocusInWindow() on the first JTestBox simply don't work.
    - Peter

  • ComboBoxControl - JD3 documentation doesn't seem to apply

    QUESTION: Is it now NOT possible to use the ComboBoxControl in JD3 as in JD2?
    BACKGROUND INFO:
    In JD2,
    I navigate through the rows of a column after binding a ComboBoxControl to that column. Then, using a second ComboBoxControl (whose contructor contains an array of strings) update the value of a second column in the row selected by the first ComboBoxControl (the value = the string that I select in the second ComboBoxControl).
    However, in JD3,
    I can, once again, navigate thru the rows of a column as in JD2. But, I can NOT update the value of a second column in the row selected by the first ComboBoxControl (with the string that I select in the second ComboBoxControl). I have followed the following JD3 Documentation:
    FROM THE JD3 DOCUMENTATION: ComboBoxControl, by default is used to update values. The dataItemUsageMode property is set to FORUPDATE and the the ComboBoxControl updates the attribute that is bound via the dataItemNameForUpdate property. The ComboBoxControl can also be used for navigation. When dataItemUsageMode is set to FOR_NAVIGATION the ComboBoxControl ceases to update and is used instead to navigate through the values that are bound via the _dataItemName property.
    null

    PLEASE DISREGARD THE ABOVE.
    I TRIED THIS AGAIN, AND EVERYTHING SEEMED TO WORK FINE THE SECOND TIME.
    THANK YOU.

  • Bug in BasicTabbedPaneUI Action keys?

    Can someone tell me if the following is a bug or purposeful behavior:
    in jdk1.4.1 I map keystroke F5 to the BasicTabbedPaneUI action "navigateNext". This action eventually gets passed down to the navigateSelectedTab(int direction) method.
    In the first switch statement, it does:
    switch(tabPlacement) {
    case NEXT:
    selectNextTab(current);
    break;
    HOWEVER, tabPlacement is defined to be SwingConstants.TOP, in fact, NEXT isn't EVER even a valid value for the JTabbedPane tabPlace. This action class therefore won't ever do anything.
    Lastly, I'd like to complain that all the action classes in BasicTabbedPaneUI are private. In fact, a lot of UI class methods are private when I'd really prefer to subclass them.
    Thanks.

    Yes, that looks like a bug to me. The NEXT and PREVIOUS values are supposed to indicate the direction of navigation, not the placement of the tabs. They should either check for those values before going into the switch, or add them to the inner switches, after the tab placement has been determined.
    Those two values were added to SwingConstants in jdk1.4, and it looks like someone screwed up retrofitting BasicTabbedPaneUI to use them. (This is exactly the kind of bug that typesafe enums are meant to prevent; too bad we had to wait until jdk1.5 for those.) Do you want to file the bug report, or should I?

  • Can't drag the border of JTabbedPane

    Hi,
    I met a problem in programming JTabbedPane. I am now fixing some bugs in a existing project, so I am not familar with JTabbedPane.
    In my case, I am not able to adjust the size of JTabbedPane by dragging the border of it. This JTabbedPane is in the right side of a JSplitPane. However, if the right side pane is replaced by a JLabel, then I can drag the border of JLabel.
    I don't why it happens? Does this mean once a JTabbedPane is created (includes it's component inside), I can't change it size anymore? Is there any one who can give me any ideas?
    Thanks
    Feng

    Yes, I also got this conclusion. The problem is caused by the size of inside component.
    There are one JLabel and one JTextField inside my JToolbar. If the string in the JTextField is short, I am able to adjust the width of JToolbar, however, only made it bigger. But if the text inside the JTextField is longer than than the width of screen. the edge of JToolbar is no longer able to be adjusted.
    I know the cause is the size of text in the JTextField. It made the JTextField very long. I know the reason, but I don't know how to solve it. Any one could help me for that?
    Thanks
    Feng

  • BUG REPORT: 2 JTextComponents using the same Document

    When 2 JTextComponents use the same Document they should show the same.
    However when you add them to JTabbedPane to 2 different tabs, one does not show the document correctly, until you resize the window.
    Compile and run the code example to see for yourself.
    If you append "<first message"> and "<second message>" the first tab will show the correct document:
    <first message>
    <second message>
    But if you then switch to the second tab (do not switch to it earlier), you will see:
    <first message><second message>
    <second message>
    Add some more messages to see the effect and then resize the window to see the problem dissappear magically.
    --> Code example <--
    package testproject;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    * @author Geoffrey
    public class TestProject extends JFrame implements ActionListener {
         public static void main(String[] args) {
              TestProject currentFrame = new TestProject();
              currentFrame.pack();
              currentFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Optional
              currentFrame.setVisible(true);
         private JLabel label = new JLabel("Append 2 or more different messages and switch tab. "
         + "Resizing the window will solve the bug.");
         private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP,
                                                                                         JTabbedPane.WRAP_TAB_LAYOUT);
         private JTextField textField = new JTextField("<first message>");
         private JButton button = new JButton("Append message");
         private StyledDocument document = new DefaultStyledDocument();
         private JTextPane firstTextPane;
         private JTextPane secondTextPane;
         public TestProject() {
              super("TestProject");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              // configure the components
              firstTextPane = new JTextPane(document); // Uses the same document as secondTextPane
              tabbedPane.add("Orginal tab", firstTextPane);
              secondTextPane = new JTextPane(document); // Uses the same document as firstTextPane
              tabbedPane.add("Click here after appending 2 different messages", secondTextPane);
              textField.addActionListener(this);
              button.addActionListener(this);
              // configure the layout and add the components
              Container contentPanel = getContentPane();
              GridBagLayout layout = new GridBagLayout();
              contentPanel.setLayout(layout);
    GridBagConstraints constraints = new GridBagConstraints();
              constraints.fill = GridBagConstraints.BOTH;
              constraints.insets = new Insets (10, 10, 10, 10);
              constraints.weightx = 1.0;
              constraints.weighty = 0.0;
              constraints.gridx = 0;
              constraints.gridy = 0;
              contentPanel.add(label, constraints);
              constraints.weighty = 1.0;
              constraints.gridy = 1;
              contentPanel.add(tabbedPane, constraints);
              constraints.weighty = 0.0;
              constraints.gridy = 2;
              contentPanel.add(textField, constraints);
              constraints.gridy = 3;
              contentPanel.add(button, constraints);
         public void actionPerformed(ActionEvent event) {
              String message = textField.getText();
              SimpleAttributeSet simpleAttributeSet = new SimpleAttributeSet();
              StyleConstants.setFontFamily(simpleAttributeSet, "Monospaced");
              StyleConstants.setForeground(simpleAttributeSet, Color.BLACK);
              try {
                   document.insertString(document.getLength(), message + "\n",
                                                      simpleAttributeSet);
              } catch (BadLocationException exception) {}

    duplicate of:
    Table Location Error Oracle and SqlServer
    closing and locking
    Ludek

  • Strangeness Using HTML with JTabbedPane

    I'm getting some weird behavior when using html format for a JTabbedPane. It seems when I create tabs using HTML, it works fine, but when I subsequently try to change the tab title using JTabbedPane.setTitleAt(), the title doesn't change. The title doesn't change only when I create it with html. If I use "normal" text, the title changes fine.
    I imagine JTabbedPane has a problem with html. I am using version 1.3 and compiling with JBuilder. Below is an example of my program. Uncomment mentioned lines to see it react strangely.
    Any help would be appreciated.
    -joel
    package junk;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: " +
    "<font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: " +
    "<font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    // tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
         System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: <font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: <font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

  • Color behind the tabbs of JTabbedPane in SCROLL layout

    Hi all, This is a repost as no one gave me a solution for this problem.
    When SCROLL_TAB_LAYOUT is specified, the color behind the tabbs is not the color of its container. With WRAP layout, the color behind the tabbs is the color of its container.
    Is this a bug? or am I doing wrong?
    If one can execute this code, it would be clear of what I am talking about. Just comment out the tabbPane.setTabLayoutPolicy line and run it again to see the actual behaviour.
    JTabbedPane tabbPane = new JTabbedPane();
    tabbPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbPane.setBackground(Color.white);
    tabbPane.add("one",new JPanel());
    tabbPane.add("two",new JPanel());
    JPanel parentPanel = new JPanel(new BorderLayout());
    parentPanel.setBackground(Color.red); // the color i want to be appeared as the background for tabbed pane and not for tabbs.
    parentPanel.add(tabbPane,BorderLayout.CENTER);
    JFrame jf = new JFrame();
    jf.getContentPane().add(parentPanel);
    jf.pack();
    jf.setVisible(true);
    Thanks in advance.

    Maybe this:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4690946
    Bug ID:      4690946
    Votes      6
    Synopsis      REGRESSION: JTabbedPane.setBackground() and setOpaque() have no effect
    Category      java:classes_swing
    Reported Against      1.4
    Release Fixed      1.5(tiger)
    State      Closed, fixed

  • Focus-requests when switching tabs in JTabbedPane

    I have a tabbed pane with a JTextArea in each tab. I would like to switch focus to the corresponding area each time I select a tab or create a new one. A ChangeListener can detect tab selections and call requestFocusInWindow() on the newly chosen tab's text area.
    For some reason, the focus only switches sporadically. Sometimes the caret appears to stay, sometimes it only blinks once, and sometimes it never appears. My friend's workaround is to call requestFocusInWindow() again after the setSelectedIndex() calls, along with a Thread.sleep() delay between them. Oddly, in my test application the delay and extra focus-request call are only necessary when creating tabs automatically, rather than through a button or shortcut key.
    Does the problem lie in separate thread access on the same objects? I tried using "synchronized" to no avail, but EventQueue.invokeLater() on the focus request worked. Unfortunately, neither the delay nor invokeLater worked in all situations in my real-world application. Might this be a Swing bug, or have I missed something?
    Feel free to tinker with my test application:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    /**Creates a tabbed pane with scrollable text areas in each tab.
    * Each time a tab is created or selected, the focus should switch to the
    * text area so that the cursor appears and the user can immediately type
    * in the area.
    public class FocusTest2 extends JFrame {
         private static JTabbedPane tabbedPane = null;
         private static JTextArea[] textAreas = new JTextArea[100];
         private static int textAreasIndex = 0;
         private static JButton newTabButton = null;
         /**Creates a FocusTest2 object and automatically creates several
          * tabs to demonstrate the focus switching.  A delay between creating
          * the new tab and switching focus to it is apparently necessary to
          * successfully switch the focus.  This delay does not seem to be
          * necessary when the user fires an action to create new tabs, though.
          * @param args
         public static void main(String[] args) {
              FocusTest2 focusTest = new FocusTest2();
              focusTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              focusTest.show();
              //Opens several tabs.
              for (int i = 0; i < 4; i++) {
                   try {
                        //adding the tab should automatically invoke setFocus()
                        //through the tabbed pane's ChangeListener, but for some
                        //reason the focus often doesn't switch or at least doesn't
                        //remain in the text area.  The workaround is to pause
                        //for a moment, then call setFocus() directly
                        addTabbedPaneTab();
                        //without this delay, the focus only switches sporadically to
                        //the text area
                        Thread.sleep(100);
                        setFocus();
                        //extra delay simply for the user to view the tab additions
                        Thread.sleep(1900);
                   } catch (InterruptedException e) {
         /**Adds a new tab, titling it according to the index of its text area.
          * Using "synchronized" here doesn't seem to solve the focus problem.
         public static void addTabbedPaneTab() {
              if (textAreasIndex < textAreas.length) { //ensure that array has room
                   textAreas[textAreasIndex] = new JTextArea();
                   //title text area with index number
                   tabbedPane.addTab(
                        textAreasIndex + "",
                        new JScrollPane(textAreas[textAreasIndex]));
                   tabbedPane.setSelectedIndex(textAreasIndex++);
         /**Constructs the tabbed pane interface.
         public FocusTest2() {
              setSize(300, 300);
              tabbedPane = new JTabbedPane();
              //Action to create new tabs
              Action newTabAction = new AbstractAction("New") {
                   public void actionPerformed(ActionEvent evt) {
                        addTabbedPaneTab();
              //in my real-world application, adding new tabs via a button successfully
              //shifted the focus, but doing so via the shortcut key did not;
              //both techniques work here, though
              newTabAction.putValue(
                   Action.ACCELERATOR_KEY,
                   KeyStroke.getKeyStroke("alt T"));
              newTabAction.putValue(Action.SHORT_DESCRIPTION, "New");
              newTabAction.putValue(Action.MNEMONIC_KEY, new Integer('T'));
              newTabButton = new JButton(newTabAction);
              Container container = getContentPane();
              container.add(tabbedPane, BorderLayout.CENTER);
              container.add(newTabButton, BorderLayout.SOUTH);
              //switch focus to the newly selected tab, including newly created ones
              tabbedPane.addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent evt) {
                        //note that no delay is necessary for some reason
                        setFocus();
         /**Sets the focus onto the selected tab's text area.  The cursor should
          * blink so that the user can start typing immediately.  In tests without
          * the delay during the automatic tab creation in main(), the cursor
          * sometimes only blinked once in the text area.
         public static void setFocus() {
              if (tabbedPane == null) //make sure that the tabbed Pane is valid
                   return;
              int i = tabbedPane.getSelectedIndex();
              if (i < 0) //i returns -1 if nothing selected
                   return;
              int index = Integer.parseInt(tabbedPane.getTitleAt(i));
              textAreas[index].requestFocusInWindow();
    }

    Did you ever get everything figured out with this? I have a similar problem ... which I have working, but it seems like I had to use a bunch of hacks.
    I think the problem with the mouse clicks is because each event when you click the moues (mousePressed, mouseReleased, mouseClicked) causes the tab to switch, and also these methods are called twice for some reason - for a total of 8 events giving the tab the focus instead of your textarea.
    This works, but seems aweful hacky:
         class TabMouseListener extends MouseAdapter
              private boolean switched = false;
              public void mousePressed( MouseEvent e ) { checkPop( e ); }
              //public void mouseReleased( MouseEvent e ) { checkPop( e ); }
              //public void mouseClicked( MouseEvent e ) { checkPop( e ); }
              public void checkPop( MouseEvent e )
                   if( e.isPopupTrigger() )
                        mousex = e.getX();
                        mousey = e.getY();
                        int index = tabPane.indexAtLocation( mousex, mousey );
                        if( index == -1 ) return;
                        tabMenu.show( tabPane, mousex, mousey );
                   else {
                        if( !switched )
                             switched = true;
                             e.consume();
                             int index = tabPane.indexAtLocation( e.getX(), e.getY() );
                             if( index != -1 )
                                  tabPane.setSelectedIndex( index );
                                  TabFramePanel panel = (TabFramePanel)tabPane.getComponentAt( index );
                                  if( panel != null ) panel.getInputComponent().requestFocus();
                        else {
                             switched = false;
                             TabFramePanel panel = (TabFramePanel)tabPane.getSelectedComponent();
                             if( panel != null ) panel.getInputComponent().requestFocus();
         }Do you know of a better way yet?
    Adam

  • Strange JTabbedPane behaviour

    In my application I need tabs only, i.e., without the content area. I'm trying to achieve that by adding JComponent with (1,1) dimensions. But the more tabs I add the bigger the size of JTabbedPane becomes. Is it a bug?
    Here is a simple testcase:
    package tabtest;
    import java.awt.Dimension;
    import javax.swing.JComponent;
    public class NewJFrame extends javax.swing.JFrame {
        public NewJFrame() {
            jSplitPane1 = new javax.swing.JSplitPane();
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jLabel2 = new javax.swing.JLabel();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jButton1 = new javax.swing.JButton();
            jButton1.setPreferredSize(new Dimension(100,50));
            jPanel1.setPreferredSize(new Dimension(500, 200));
            this.setSize(800,600);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
            jPanel1.setLayout(new java.awt.BorderLayout());
            jLabel2.setText("jLabel2");
            jPanel2.add(jLabel2);
            jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);
            jPanel1.add(jTabbedPane1, java.awt.BorderLayout.NORTH);
            jSplitPane1.setLeftComponent(jPanel1);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jSplitPane1.setRightComponent(jButton1);
            getContentPane().add(jSplitPane1, java.awt.BorderLayout.NORTH);
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            TestComponent tc=new TestComponent();
            tc.setSize(1,1);
            tc.setPreferredSize(new Dimension(1,1));
            jTabbedPane1.addTab("Tab "+Integer.toString(jTabbedPane1.getComponentCount()),null,tc, "Tab "+Integer.toString(jTabbedPane1.getComponentCount()));
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JSplitPane jSplitPane1;
        private javax.swing.JTabbedPane jTabbedPane1;
    /** JComponent class to be used with JTabbedPane
    class TestComponent extends JComponent{
    }It adds a new tab each time the button is clicked, and with each click it moves jLabel2 down. You may test it to see how the size of JTabbedPane grow.
    Does anyone have ideas why it behaves so? Is there any other way to get tabs without content area?

    Indeed. Most obvious solution, but I've forgot about that. Thanks, that resolved the issue.
    Still, I'm curious why the JTabbedPane keeps growing? As far as I understand the size of JTabbedPane equals the size of the biggest component, isn't it?

Maybe you are looking for