Java Swing - proper tabbed windows

Discussion in 'Mac Programming' started by AlmostThere, Apr 17, 2007.

  1. AlmostThere macrumors 6502a

    #1
    Does anyone know what Swing class I need to use to create tabs like these, or, for example, like those in Safari although not a Java app (some of these screens are from Windows, but as I have used both these apps, the behaviour is the same):

    http://www.jformdesigner.com/screenshots/images/mac_os_x.png where the "FormsTutorial" is on a tab.

    http://www.jformdesigner.com/screenshots/images/main_move_row.png where "FormSpecPanel", "GridBagLayoutUI" and "TableLayoutUI" are tabs

    More examples:

    http://www.aquafold.com/6.0screens/main-visualexplaintree-large.jpg where "sa@SQL Server ... " is on a closeable tab
    and
    http://www.aquafold.com/6.0screens/docs/osx-in-action-large.jpg showing two sets of tabs.

    These are closeable in the actual app and are obviously different from the vanilla JTabbedPane.

    I know there is a Java 6 tutorial explaining this on the Sun website but I am running (and will be for the foreseeable future) Java 5.

    Also, I vaguely remember some tool that allowed to identify the class of a Swing component from a running app - but maybe I am mistaken. Does this ring any bells with anyone?

    Thanks
     
  2. therevolution macrumors 6502

    Joined:
    May 12, 2003
    #2
    Those apps look like they were built on the Eclipse Rich Client Platform. If you want your app to have a similar layout, you should check it out.

    Otherwise, look at using JTabbedPane with a different Look and Feel package. I'm not sure which one would give you the exact same look, so you'll have to search. You could subclass JTabbedPane to add the close-button-on-tab functionality.
     
  3. Sir Al macrumors member

    Sir Al

    Joined:
    Feb 14, 2005
    Location:
    Vancouver, Canada
    #3
    Also, it looks like these are using SWT, not Swing.
     
  4. AlmostThere thread starter macrumors 6502a

    #4
    As far as I can see, neither of these apps come bundled with the swt jar file or jnilibs, hence I guessed they were swing.

    SWT, which I have been using, is not really an alternative - I need to use some 3rd party Swing components and have had no end of problems with the SWT_AWT bridge on OS X (and yes, I have all the updates that supposedly fixed these issues).
     
  5. ryan macrumors 6502

    Joined:
    May 17, 2002
    Location:
    Denver, CO
  6. abcfob macrumors newbie

    Joined:
    Apr 10, 2007
    #6
    Have you tried a JTabbedPane?

    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTabbedPane.html

    all you would have to do is add your swing components using the addTab(String,Component) method.

    [EDIT]
    Ah, I see you're already familiar with that, if you want to add the "X" to close the tab, you would have to add mouse listeners to the tab to track the mouse movement, and add custom code to display the "x". It would be easier to just include a JButton on the side which would close the currently selected tab in the JTabbedPane.

    If you want to know what class your component is, you can use instanceof such as

    if(pComponent instanceof JLabel){
    //do something
    }

    [Edit2]

    Typing "closeable swing tabs" in google yields links with examples of people doing what you want
    here's one for example: http://forum.java.sun.com/thread.jspa?threadID=760307&messageID=4343391
     
  7. AlmostThere thread starter macrumors 6502a

    #7
    I saw that thread and will have a look at the JGoodies stuff as well. I will have a play with these (although I might have a hard time pushing for the JGoodies licences on what is essentially an R&D project).

    I was just wondering if there was a standard widget that gave the behaviour I am looking for, especially having seen similar behaviour in other apps. It has been a few years since I did much swing and know it has come on quite a bit in that time.

    Thanks for all the input.
     

Share This Page