bug using a JTabbedPane

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

bug using a JTabbedPane

Postby mike » Tue Sep 28, 2004 3:51 am

I'm evaluating the SWT-Designer and have found a bug using a JTabbedPane!

I've created a new JFrame, set the layout to "BorderLayout" and placed a JTabbedPane in the middle (center) of the contentPane.
Then I've added a new tab (JPanel) to the JTabbedPane. Next I've set a label to the new created tab. (see attached print screen)

When I run the generated main-class so I don't see the tab!

In the generated source code, the method to add the JPanel will never be called! (see source code snip below)

Do you know this bug?
Is there a simple solution to resolve this problem?

Greets, Mike


Code: Select all
public class TabbedPaneTest extends JFrame
{

  private JLabel label;
  private JPanel panel;
  private JTabbedPane tabbedPane;
  public static void main(String args[])
  {
    TabbedPaneTest frame = new TabbedPaneTest();
    frame.setBounds(100, 100, 500, 375);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }
  public TabbedPaneTest()
  {
    super();
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(getTabbedPane(), BorderLayout.CENTER);
    //
  }
  protected JTabbedPane getTabbedPane()
  {
    if (tabbedPane == null) {
      tabbedPane = new JTabbedPane();
    }
    return tabbedPane;
  }
  protected JPanel getPanel() // --> Will be never done! <-- \\
  {
    if (panel == null) {
      panel = new JPanel();
      getTabbedPane().addTab("New tab", null, panel, null);
      panel.add(getLabel());
    }
    return panel;
  }
  protected JLabel getLabel()
  {
    if (label == null) {
      label = new JLabel();
      label.setText("New JLabel");
    }
    return label;
  }
}
mike
 

Re: bug using a JTabbedPane

Postby Eric Clayberg » Tue Sep 28, 2004 8:48 am

mike wrote:I've created a new JFrame, set the layout to "BorderLayout" and placed a JTabbedPane in the middle (center) of the contentPane. Then I've added a new tab (JPanel) to the JTabbedPane. Next I've set a label to the new created tab. (see attached print screen) When I run the generated main-class so I don't see the tab! In the generated source code, the method to add the JPanel will never be called! (see source code snip below) Do you know this bug?

The problem is isolated to the accessor creation code gen mode. It works fine in the other code gen modes. Turning off the accessor creation mode will avoid the problem.

To quickly fix the generated code, either add a call to getPanel() to the getTabbedPane() method or move the call to "getTabbedPane().addTab("New tab", null, panel, null);" to the getTabbedPane() method (and replace the "panel" reference with a call to getPanel()).

A new v2.1.1 build is available that fixes the accessor mode code gen problem.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Cannot add JPane to JTabbedPane at all etc.

Postby teirrah » Thu Jan 06, 2005 6:50 pm

trying to add a JPane to a JTabbedPane I get an errormessage (see stack trace below) - the entry doesn't show in the designerview - it appears for some time in the designertree and thereafter is ignored by the designer.
the code works if i run it.. but i can't work with the panel i create in the designer..

another thing what makes it difficult to rely on runnable code - the designer produces this code:
(1) final JMenu menu = new JMenu();
(2) menu.setDisplayedMnemonicIndex(0);
(3) menuBar.add(menu);
(4) menu.setText("MyMenuText");
at least i don't get this compiled (java.lang.IllegalArgumentException) - line (2) needs to be set after line (4)

there's a last problem and i don't know if the designer is to blame for that, because i can't and don't want to reproduce it: did your code ever get totally messed up? there were letters and words missing, other words totally mixed up..
and did you before also experience that you couldn't select items in the designer-view, only in the tree?

and after all - still - i apprechiate the tool and hope to find some workarounds. maybe someone can help me..
thx


here's the stack trace of my major problem:

Problems occurred when invoking code from plug-in: "org.eclipse.core.runtime".

java.lang.NullPointerException
at com.swtdesigner.model.swing.component.tab.JTabbedPaneTabInfo.getPropertyList(SourceFile:83)
at com.swtdesigner.model.JavaInfo.getProperties(SourceFile:5411)
at com.swtdesigner.model.JavaInfo.getNonEventProperties(SourceFile:5441)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.showJavaInfoInPropertyTable(SourceFile:653)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite.refreshSelectedWidget(SourceFile:558)
at com.swtdesigner.gef.common.property.DesignerEditorPropertyComposite$2.selectionChanged(SourceFile:213)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:159)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:616)
at org.eclipse.core.runtime.Platform.run(Platform.java:747)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:157)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1394)
at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:693)
at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:718)
at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:180)
at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:175)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:324)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
teirrah
 
Posts: 1
Joined: Thu Jan 06, 2005 4:29 pm

Re: Cannot add JPane to JTabbedPane at all etc.

Postby Eric Clayberg » Sat Jan 08, 2005 4:59 pm

teirrah wrote:trying to add a JPane to a JTabbedPane I get an errormessage (see stack trace below) - the entry doesn't show in the designerview - it appears for some time in the designertree and thereafter is ignored by the designer.
the code works if i run it.. but i can't work with the panel i create in the designer.

I could not reproduce this problem. Can you send us a test case?

teirrah wrote:another thing what makes it difficult to rely on runnable code - the designer produces this code:
(1) final JMenu menu = new JMenu();
(2) menu.setDisplayedMnemonicIndex(0);
(3) menuBar.add(menu);
(4) menu.setText("MyMenuText");
at least i don't get this compiled (java.lang.IllegalArgumentException) - line (2) needs to be set after line (4)

This has been fixed in the latest v3.0.1 build.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: Google [Bot] and 1 guest