Updating component within awt-event thread of another component

Hi,
I'm having trouble updating (repainting) a component inside the awt-event thread of another component. The component I want to update is a JFrame with a JLabel that lists the progress of the original component's action that triggered the event. I can get the frame to pop up but it's content is never fully painted and never refreshed.
I've tried using invokeLater() (the frame ran after the original awt-event had finished) and invokeAndWait() (blocked the original awt-event) and running the computational intensive parts of the original component's action in SwingWorker threads (no difference) but all to no avail.
What I want to do is similar to a progress bar so I think it should possible. Any suggestions? Thanks, Matt

Are you calling yield() or sleep(...) on your Thread?

Similar Messages

  • Synchronize AccessBridge thread with AWT event thread?

    Hi,
    I am a beginner in Java Access Bridge.
    I am writing a program that runs with Java Web Start and uses JFC Swing. For system monitoring purpose my company uses HP OpenView. Probe Builder is used for recording a probe for the application. The probe will be run at regular intervals to check if anything is broken. As I understand Probe Builder uses Java Access Bridge to record & control the application flow.
    Without Java Access Bridge my program runs fine. But when I run it with Probe Builder I occasionally catch some exceptions that indicate that there are two threads running over my gui classes at the same time, the AWT event thread and another thread that comes from com.sun.java.accessibility.AccessBridge.run.
    Since my classes are not thread safe (like all the Swing classes) there are race conditions that result in a NullPointerException.
    My question is that how can I make sure that only one thread at a time is running over my code? Can I somehow make Java Access Bridge run with the AWT event thread? Or do I have to synchronize all my methods - I want to avoid this since I am not sure that this can be done perfectly.
    I will appreciate any help.
    Thanks
    Message was edited by:
    karneim

    Maybe there is some other way to "kill" this thread because for some specific reasons I don't think I will be able to use System.exit(). This reason is - I'm using this Java program in Lotus Notes (don't know if you have had any experience with this) and if I call System.exit() then some important clean-up (garbage collection) won't be done.

  • AWT Event Thread dying

    Hi All
    I am using a JTree and I will add some data to the JTree. Then I am removing that data from its original location.What is happening is that in the JTree paint method its calling DefaultMutableTreeNode.toString() which will call myObject.toString() .Since I have deleted these objects it will throw Exceptions .Since these Exceptions are thrown in EventThread some times the Application ghet crashed . Can anybody suggest me some solurtion for this?
    Thanks
    Pradeep

    Hi
    Thanks for the reply. How can I know when the file is deleted. Is there any listener for that?. Actually I tried Tree listener, but it didnot catch any events.
    Thanks
    Pradeep

  • Field in one component to be made available in another component

    Hi,
    My requirement is as follows:
    I have to bring the email address field of component BP_CONT to the lead component.
    When i create lead on the UI and select a prospect then the email address of the prospect should appear in this field (this field can be further edited and the master data of prospect should be updated accordingly).
    Till now i have enhanced the component controller and redefined method wd_usage_initialize.
    I am getting the email field on the UI but when i select a prospect the email address of this prospect is not being displayed in this field.
    Please help!
    I am absolutely new to all this.
    Regards
    Shilpi

    Hi Shilpi,
    You can create a component usage in the component where you want the filed to be present of the component where the field is presently.
    You can then bring the field on the UI in the desired area.
    You should be able to save the data with this approach.
    Kindly reward points if this helps
    Regards,
    Praveen

  • View of one component need to be used in another component.

    Hi Experts,
    I have created a view in component  BP_DATA . I want to use this view in component "BP_HEAD". Can anyone please help me with the steps needed to make the view available in  BP_DATA. Do i need to do any type of binding for this.

    Hello Ansal,
    For using BP_DATA/yourview in component BP_HEAD, first you will have to expose BP_DATA view in component interface. Then you can access that view in BP_HEAD by creating component usage. Once you add the view of BP_DATA in component usage of BP_HEAD, it will be available as a normal view in this component.
    -Regards

  • AWT idle event thread?

    Does anyone have an example of how to create an
    AWT "busy" Dialog? I'd like to have a modal dialog
    come up that says my applet is doing some task,
    and when that task is complete, the Dialog should
    go away. So, typically, the user would not click
    anything in the dialog, it would just go away when
    the task finishes.
    What I now do is call show() from the event thread,
    and also span a new thread to do the actual work and
    when the work is complete, my new thread (not
    the AWT event thread) gets rid of the busy dialog.
    However, this seems to result in a hung UI most
    of the time with IE.
    I suspect maybe if the event thread got rid of the
    Dialog instead of my other thread the UI hang might
    not happen.
    Is there a way I can create tell AWT to run an idle
    thread (ie, when it's not doing anything)? If I could
    do that, then I could let the AWT event thread get
    rid of my dialog.
    Thank you!

    First of all, there is no way to create a modal dialog for an applet. Because the constructor of modal dialog needs a Dialog or Frame object as its owner. Unfortunately, the applet subclasses Panel that is in the hierarchy that is other than Dialog and Frame's. You can think in this way the applet does not own the browser's window.
    The dialog created by an applet sometimes get UI frozen. The reason is that the thread you created for the dialog is in the same thread group, sun.applet.AppletThreadGroup where the dialog thread can not get enough time slices to run.
    What I have done to solve this problem is to create the dialog thread under main thread group. I list the source code below for your reference.
    ThreadGroup group = Thread.currentThread().getThreadGroup();
    while(!group.getName().equals("main"))
    group = group.getParent();
    new Thread(group, this, "BusyDialog").start();

  • JTable Awt -Event Queue problem

    Hi
    I've been looking everywhere for a solution to this, but can't seem to find one. I've got a JTable with an underlying model that is being continuously updated (every 100ms or so). Whenever I try to sort the JTable using TableRowSorter while the model is being added to I get
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.Vector.elementAt(Vector.java:430)
    at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:277)
    I don't understand this as in my custom table model I've added the fireTableChanged etc. in a SwingUtilities.invokeLater( ...) thread.
    Has anyone else encountered this problem and found a solution? I'd be really grateful!
    Thanks

    Hi
    Thanks for responding, I'm still a little confused. I've posted the code below for both the JTable and the TableModel. The tablemodel simply gets values from a vector which is being dynamically updated from outside the table - but whenever the vector is added to
    The problem seems to only occur when I press the column header to sort the tables during the updates. My understanding is that the method refresh() should create a threadsafe update of the table - but somehow it refreshes the binding to the tablemodel and during this time the table returns a defaulttablemodel that doesn't correspond to the actual underlying data....I thought this kind of problem would be solved by invoking all updates on the swing event thread, but it seems to still produce the effect and I'm stumped!!
    (The data is in an array called turns, and the addElement() in another class calls the refresh() method)
    many thanks, in the hope that someone has the kindness and and benevolence to wade through the following code!
    public class JContiguousTurnsListTable extends JTable {
    private JContiguousTurnsListTableModel jctltm;
    public JContiguousTurnsListTable(Conversation c) {
    super();
    jctltm = new JContiguousTurnsListTableModel(this,c);
    this.setModel(jctltm);
    setSize();
    //this.setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
    //this.setAutoCreateRowSorter(true);
    TableRowSorter <TableModel> sorter = new TableRowSorter <TableModel>(jctltm);
    //sorter.setSortsOnUpdates(true);
    this.setRowSorter(sorter);
    System.err.println("Setting up ");
    private void setSize(){
    TableColumn column = null;
    for (int i = 0; i <11; i++) {
    column = this.getColumnModel().getColumn(i);
    if(i==1||i==2||i==3||i==4||i==8||i==9){
    column.setPreferredWidth(50);
    else if (i==0||i==5){
    column.setPreferredWidth(180);
    else if (i == 6) {
    column.setPreferredWidth(150);
    else if(i==10){
    column.setPreferredWidth(250);
    else
    column.setPreferredWidth(100);
    //column.setPreferredWidth(100);
    //column.setMinWidth(100);
    //column.setMaxWidth(100);
    public String getColumnName(int column){
    return jctltm.getColumnName(column);
    public void refresh(){
    this.jctltm.refresh();
    ----------------And the table model:
    public class JContiguousTurnsListTableModel extends AbstractTableModel {
    private Conversation c;
    public JContiguousTurnsListTableModel(JTable jt,Conversation c) {
    super();
    this.c=c;
    public void refresh(){
    //System.out.println("Refresh");
    SwingUtilities.invokeLater(new Runnable(){public void run(){fireTableDataChanged();fireTableStructureChanged();} });
    public boolean isCellEditable(int x, int y){
    return false;
    public String getColumnName(int column){
    if(column==0){
    return "Sender";
    else if(column==1){
    return "Onset";
    else if (column==2){
    return "Enter";
    else if(column ==3){
    return "E - O";
    else if(column ==4){
    return "Speed";
    else if(column ==5){
    return "Spoof Orig.";
    else if(column ==6){
    return "Text";
    else if(column ==7){
    return "Recipients";
    else if(column ==8){
    return "Blocked";
    else if(column ==9){
    return "Dels";
    else if(column ==10){
    return "TaggedText";
    else if(column ==11){
    return "ContgNo";
    else if(column ==12){
    return "Inconcistency";
    else{
    return " ";
    public Object getValueAt(int x, int y){
    try{ 
    //System.out.println("GET VALUE AT "+x+" "+y);
    Vector turns = c.getContiguousTurns();
    if(x>=turns.size())return " ";
    ContiguousTurn t = (ContiguousTurn)turns.elementAt(x);
    if(y==0){
    return t.getSender().getUsername();
    else if(y==1){
    return t.getTypingOnset();
    else if(y==2){
    return t.getTypingReturnPressed();
    else if(y==3){
    return t.getTypingReturnPressed()-t.getTypingOnset();
    else if(y==4){
    long typingtime = t.getTypingReturnPressed()-t.getTypingOnset();
    if(typingtime<=0)return 0;
    return ((long)t.getTextString().length())/typingtime;
    else if(y==5){
    return t.getApparentSender().getUsername();
    else if(y==6){
    return t.getTextString();
    else if(y==7){
    //System.out.println("GETTINGRECIP1");
    Vector v = t.getRecipients();
    String names ="";
    // System.out.println("GETTINGRECIP3");
    for(int i=0;i<v.size();i++){
    Conversant c = (Conversant)v.elementAt(i);
    // System.out.println("GETTINGRECIP4");
    names = names+", "+c.getUsername();
    // System.out.println("GETTINGRECIP5");
    return names;
    else if (y==8){
    if (t.getTypingWasBlockedDuringTyping())return "BLOCKED";
    return "OK";
    else if(y==9){
    return t.getNumberOfDeletes();
    else if(y==10){
    String returnText="";
    Vector v = t.getWordsAsLexicalEntries();
    for(int i=0;i<v.size();i++){
    LexiconEntry lxe= (LexiconEntry)v.elementAt(i);
    returnText = returnText+lxe.getWord()+" ("+lxe.getPartOfSpeech()+") ";
    return returnText;
    else if(y==11){
    return t.getNumberOfTurns();
    else if(y==12){
    // System.out.println("CONTIGUOUS1");
    String value ="";
    boolean hasSameRecipients = t.getTurnsHaveSameRecipients();
    boolean hasSameApparentOrigin = t.getTurnsHaveSameApparentOrigin();
    if (hasSameRecipients&hasSameApparentOrigin){
    value = "OK";
    else if (hasSameRecipients&!hasSameApparentOrigin){
    value = "Diff. O";
    else if(!hasSameRecipients&hasSameApparentOrigin){
    value = "Diff. Recip";
    else {
    value = "Diff O&R";
    //System.out.println("CONTIGUOUS2");
    return value;
    return " ";
    }catch (Exception e){
    return "UI ERROR";
    public Class getColumnClass(int column) {
    Class returnValue;
    if ((column >= 0) && (column < getColumnCount())) {
    returnValue = getValueAt(0, column).getClass();
    } else {
    returnValue = Object.class;
    return returnValue;
    public int getRowCount(){
    return this.c.getContiguousTurns().size();
    public int getColumnCount(){
    return 13;
    }

  • Flags and the Event Thread

    I was writing code for a game and I realized that the AWT event thread could change the value of a flag while I'm in the process of updating the game state. This can cause a few problems, or it could even leave events not handled because of it. I see code like this all the time as a fix to the threading issues, am I missing something or is it really a solution? I can't post the actual code as it's too long, so I created a simple example:
    import java.awt.event.*;
    import javax.swing.*;
    public class EventTest extends JFrame implements KeyListener, Runnable
         private boolean isKeyDown;
         public EventTest()
              setSize(500, 500);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setVisible(true);
              addKeyListener(this);
              new Thread(this).start();
         public void keyPressed(KeyEvent event)
              //synchronized(this)
                   isKeyDown = true;
         public void keyReleased(KeyEvent event)
              //synchronized(this)
                   isKeyDown = false;
         public void keyTyped(KeyEvent event) {}
         public void run()
              // game loop
              while(true)
                   //synchronized(this)
                        boolean cache = isKeyDown;
                        System.out.print(isKeyDown); // before
                        System.out.print(' ');
                        /* event handling, game logic, etc. done here
                           do some useless operation to simulate this */
                        long time = System.currentTimeMillis();
                        while(time + 1 > System.currentTimeMillis());
                        System.out.println(isKeyDown); // after
                        if(cache != isKeyDown)
                             System.out.println("PROBLEM!");
                        // render everything to the screen
                   try
                        Thread.sleep(100);
                   } catch(InterruptedException e) {}
         public static void main(String[] args)
              new EventTest();
    }Basically I have a game loop, where I update the game state, handle events, then draw things to the screen. Each time a key is pressed or released, I set the appropriate value to isKeyDown from the AWT event thread. The desirable output is to have the booleans equal to each other so that "false false" or "true true" is printed out on the screen constantly, but once in a while I'll get a "false true" or "true false", which is expected but obviously not wanted.
    So one solution is right there commented out (synchronizing), though most people seem to avoid it. I see everybody using flags like this, so I'm wondering if I'm missing some obvious solution to the problem or if it's really even that big of a deal. I don't see any other fix, but that's why you're all here. ;)
    Thanks.

    Swing related questions should be posted in the Swing forum.
    I converted your simple example to use a Swing Timer instead of a while(true) loop with a Thread.sleep. I experienced no problems as expected since all the code will be executed in the Event Dispatch Thread (EDT).
    Of course using this approach could make the game less responsive if your game logic is extensive and hogs the EDT, but given that you try to invoke your game logic every 100 millisecond I assume it can't be that extensive.
    Anyway here is the code I used as a test:
    import java.awt.event.*;
    import javax.swing.*;
    public class EventTest extends JFrame implements KeyListener, ActionListener
         private boolean isKeyDown;
         public EventTest()
              setSize(500, 500);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setVisible(true);
              addKeyListener(this);
              new Timer(100, this).start();
         public void keyPressed(KeyEvent event)
              isKeyDown = true;
         public void keyReleased(KeyEvent event)
              isKeyDown = false;
         public void keyTyped(KeyEvent event) {}
         public void actionPerformed(ActionEvent e)
              boolean cache = isKeyDown;
              System.out.print(isKeyDown); // before
              System.out.print(' ');
              /* event handling, game logic, etc. done here
                 do some useless operation to simulate this */
              long time = System.currentTimeMillis();
              while(time + 1 > System.currentTimeMillis());
              System.out.println(isKeyDown); // after
              if(cache != isKeyDown)
                   System.out.println("PROBLEM!");
         public static void main(String[] args)
              new EventTest();
    }

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • Calling event called in a component but set in another?

    I have two components, both called from my main application. I've added an event listener in one of the components, but when I try to dispatch the event in the other component, nothing happens. Can anyone explain why this is please?

    It sounds like you have the following:
    Component A - has a listener attached for some event.
    Component B - dispatches the event.
    Assuming this is a correct interpretation, it's pretty clear why nothing happens. You have a listen attached to A, but A never fires the event. It is B that fires the event, but you are not listening to it. Attach the listener to B and have the handler function perform whatever operation is desired on A.

  • How to enqueue custom AWT event?

    hi,
    in my applet I need to use custom AWT events. I subclass them from java.awt.AWTEvent and set their id to higher as AWTEvent.RESERVED_ID_MAX - as recomended in documentation.
    But how to enqueue such event? A tried to use following approach:
    getToolkit().getSystemEventQueue().postEvent( myEvent );
    and it works fine - but only in browsers usings Sun's VM implementation. In browsers using Microsoft's VM I'm getting following exception:
    com.ms.security.SecurityExceptionEx[matlu/client/ClientConnection.enQueue]: Event queue access denied.
    So the question is: is there any other way to enqueue custom event, which will keep Microsoft's security manager happy?
    thak you very much
    Lubo Matecka

    I know it must be visible... (But it doesnt have to be bigger than 1 pixel...)
    The code I posted is just to illustrate the idea.
    If you need to post multiple events you just replace the AWTEvent member with a LinkedList (or some similar FIFO).
    Then in postEvent you do theLinkedList.addFirst(yourEvent)
    And in paint() you do AWTEvent ev = (AWTEvent)theLinkedList.removeLast();
    process ev.
    if(theLinkedList.size() > 0)
       repaint();Yes. I have run into the same problem, and I did not use the repaint- trick...
    My applet communicates with the server in a separate thread. When a response receives the communication thread should post an event to the AWT- thread to get the response processed.
    My solution here is to process the thread in the communicator- thread. This is a bad solution because it might create multithreading bugs.... but it has proven to work ok in practice.
    Another example is like this. The use presses the mouse at Component B so that:
    1 Component A gets a focusLost event.
    2 Component B gets a mousePressed.
    3 I want to do something in component A that should be done after component B has processed the mousePressed event. This can be solved without using events. You just have to write some more code (You are already in the right thread).

  • Swing component fires an event to non-GUI code

    Hi all -- this is my first post in forums.sun.com.
    Question to get me started -
    I have a Swing component that fires an ActionEvent. I would like that ActionEvent to trigger code that does not run on the AWT Event Queue thread (some code that will take some time without impacting GUI rendering performance.)
    I know I could put that Event's action command into a synchronized Queue, and have a worker thread checking the queue and taking action when it finds a command there. Likewise, I could flag a volatile boolean as true, and have a worker thread check the flag and take action when true.
    Or (and I suspect this is best), I could create a new SwingWorker thread right in actionPerformed().
    Any opinions on what makes sense?

    pkwooster: Yep. That's what I meant.
    As for the design pattern, Observer was the pattern I was intending to use (and have already implemented). Would anyone argue that another method is more efficient or "correct"?
    My sample project is:
    Business Object -> Main Dialog -> Embedded Dialog
    The Main Dialog contains no business logic - just simple navigation events. The Embedded Dialog contains the real controls and reports any interaction using Swing events, which the Main Dialog picks up.
    I then set up the Observer pattern between the Main Dialog and the Business Object.

  • Swing event queue, modal dialogs, event threads, etc...

    Hey all,
    So I am playing around with the focus manager, swing event thread and event queue, etc. Learned quite a bit. I am also playing around with test automation of our UI, using jfcUnit. I have written a few simple apps to play aorund with record/playback, coding tests, etc. What this thread is about though, is figuring out how modal and non-modal dialogs "take over" the event thread/queue? The reason I ask is, if I put a simple test harness like tool embeded in my app as a separate pop-up modal dialog, and from within it there is a GUI that I can use to select a "Test" to run. Now, when I run this test, jfcUnit needs to run on the main window, not within my non-modal dialog. What I am not sure of, however, is that if by using a non-modal dialog all events will go to the main event thread? I mean, I know if I mouse over my second non-modal frame (spawned from the application frame), that events will trigger for that dialog. I remember reading somewhere that modal dialogs "block" the main event queue, all left over events are given to the newly added event queue (presumably by the modal dialog) and existing left-over events get moved to the event queue. If that is the case, I am curious why events for the "old" queue are moved to the new queue if they were orginally intended for the old queue? I would think a "flush" before adding a new queue would be more appropriate so that the old queue can process all of its intended events.
    Now, I am just about to try this, but I am hoping a non-modal pop-up will not interfere with the jfcUnit running the UI of the main window. I am guessing, however, that it might. How are non-modal dialogs handled in terms of events and the event queue? Is it the same as modal dialogs? Or is there no blockage of the mainwindow event queue? If there is no blockage, than any sort of automation based on relative positions to a window may occur on the non-modal dialog, in which case it's best to hide the non-modal dialog during running of these tests.
    What are your thoughts, or better yet, knowledge of this topic? A decent explanation from a developer standpoint and not from the API's which dont give some of the more detailed info I am seeking is what I am hoping to get out of this.
    Thanks.

    Check this out. First, AWTListener has a LOT of
    different types you can register it for. I ORd all
    them together and when I ran my app, it took almost 30
    minutes for it to show up because of the huge stream
    of events being spit out via System.out. ...Yes, that doesn't surprise me in the least. There's hundreds of events that are fired around, usually unbeknownst to the user for every little thing. Lots of component and container events, in particular.
    Just make sure you OR ( using | not || ) ALL the
    "mask" values you want to watch for. That may be why
    you aren't seeing anything. When I did all that, and
    opened a menu, a ton of events came out.Maybe, I'll try that again, but I did specifically add an ActionEvent mask to get action events, and that should be all I need to get action events on buttons or menu items, and it wasn't getting them for either. It was only getting events on buttons when I used SwingEventMonitor, but not menu items.
    So I don't quite understand enough of the underlying event handling. Although, I suspect it could have something to do with the fact that these are Swing components, not AWT components (which their native peers) and it's pretty clear from AbstractButton (or was it DefaultButtonModel) how ActionEvents are fired, and they don't seem to have any connection to the code that deals with AWTListeners.
    My problem is that I kinda need a way to catch events without having a listener attached directly. Normally, I would have a listener, but there's this situation whereby an action may be triggered before I can get hold of the component to attach my listener to it. Perhaps I can get mouse press/release and just deal with it that way.
    Let me know if you did that and still didn't see what
    you were looking for. After playing with this, I am
    guessing the main reason for AWTListener is to
    register a listener for a specific type of event,
    instead of listening to them all, hence avoiding lots
    of extra overhead. Then again, the main event
    dispatcher must do a decent amount of work to fire off
    events to listeners of specific awt event types.Yes, it's definitely that. There's no point in sending events if no one is listening for it, so it does save some time.
    You are right, popup menus I think are dialogs, I
    don't know for sure, but you can access them via the
    JMenu.getPopupMenu() and JMenu.isPopupShowin().
    However, I am still not getting my test stuff working
    quite right.
    Yes, for menu popups. For a JPopupMenu on a right-click on any component (tree or whatever), I had a need to know about that from any arbitrary application (it's this GU testing app I'm working on), and since the popup menu doesn't belong to any component before it's shown, I couldn't necessarily know about it til it was displayed. I managed to use a combination of HierarchyEvents (using an AWTEventListener) and "component added" ContainerEvents. Not a simple matter, but it seems to work well.

  • A component within JTabbedPane with overlay layout

    Hi, I use the following solution to have a component within the upper right corner of the JTabbedPane: [http://forums.sun.com/thread.jspa?forumID=57&threadID=636289&start=2|http://forums.sun.com/thread.jspa?forumID=57&threadID=636289&start=2] . It works great, but when I'm resizing a window with the JTabbedPane with the JTabbedPane.WRAP_TAB_LAYOUT and width of all of the tabs is higher than size of the window the tabs are wrapped. But it should be wrapped when width of all tabs + width of the added component is higher than the size. I have no idea how to do this. Any ideas?
    Please see the screenshot: [http://img150.imageshack.us/img150/5629/btn.png|http://img150.imageshack.us/img150/5629/btn.png]

    Just a quick idea:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    class TabbedPaneTest {
      public JComponent makeUI() {
        UIManager.put("TabbedPane.tabAreaInsets",
                      new InsetsUIResource(6, 2, 0, 60));
        JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        sp.setTopComponent(makeTabPanel(new JTabbedPane()));
        sp.setBottomComponent(makeTabPanel(new ClippedTitleTabbedPane()));
        sp.setPreferredSize(new Dimension(320, 240));
        return sp;
      private JPanel makeTabPanel(final JTabbedPane tab) {
        tab.addTab("asdfasd", new JLabel("456746"));
        tab.addTab("1234123", new JScrollPane(new JTree()));
        tab.addTab("6780969", new JLabel("zxcvzxc"));
        tab.setAlignmentX(1.0f);
        tab.setAlignmentY(0.0f);
        JButton b = new JButton(new AbstractAction("add") {
          @Override public void actionPerformed(ActionEvent e) {
            tab.addTab("test", new JScrollPane(new JTree()));
        b.setAlignmentX(1.0f);
        b.setAlignmentY(0.0f);
        JPanel p = new JPanel();
        p.setLayout(new OverlayLayout(p));
        p.add(b);
        p.add(tab);
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          @Override public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new TabbedPaneTest().makeUI());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    class ClippedTitleTabbedPane extends JTabbedPane {
      //XXX Nimbus NPE
      Insets tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
      Insets tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
      public ClippedTitleTabbedPane() {
        super(JTabbedPane.TOP);
        setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        addComponentListener(new ComponentAdapter() {
          @Override public void componentResized(ComponentEvent e) {
            initTabWidth();
      @Override
      public void insertTab(String title, Icon icon, Component component,
                            String tip, int index) {
        super.insertTab(title, icon, component, tip==null?title:tip, index);
        JLabel label = new JLabel(title, JLabel.CENTER);
        Dimension dim = label.getPreferredSize();
        label.setPreferredSize(
            new Dimension(0, dim.height+tabInsets.top+tabInsets.bottom));
        setTabComponentAt(index, label);
        initTabWidth();
      private void initTabWidth() {
        Insets insets = getInsets();
        int areaWidth = getWidth() - tabAreaInsets.left - tabAreaInsets.right
                                   - insets.left        - insets.right;
        int tabCount = getTabCount();
        int tabWidth = 0;
        switch(getTabPlacement()) {
          case LEFT: case RIGHT:
          tabWidth = areaWidth/4;
          break;
          case BOTTOM: case TOP: default:
          tabWidth = areaWidth/tabCount;
        int gap = areaWidth - (tabWidth * tabCount);
        if(tabWidth>80) {
          tabWidth = 80;
          gap = 0;
        tabWidth = tabWidth - tabInsets.left - tabInsets.right - 3;
        for(int i=0;i<tabCount;i++) {
          JLabel l = (JLabel)getTabComponentAt(i);
          if(l==null) break;
          int h = l.getPreferredSize().height;
          l.setPreferredSize(new Dimension(tabWidth+((gap>0)?1:0), h));
          gap--;
        revalidate();
    }

  • MACOS 10.4: Solve AWT Event queue hangup

    Hi,
    I'm having trouble with the AWT eventqueu. On MacOS 10.4, using Java 5 Runtime, my applet sometimes blocks. When looking at the threadstack, the deadlock always appears in the Event Loop, dispatching an AWT event, blocking in the CGlobalCursorManager._updateCursor call. In fact the CGlobalCursorManager.findHeavyweightUnderCursor Native call.
    I already tried some workarounds:
    - overwrite the validate method of my custom AWT components. Making sure that they do not block forever. This solves the problem for events coming through the overidden component, but it has to work for every event that might trigger the GlobalCursorManager.
    I had some possible solutions for which I would like some pro's and con's in this forum:
    1. I could try to kill the event loop. Is it possible to quit the event loop and restart it from within the applet ?
    2. Can I force each AWT container to use another implementation of the validate method ?
    3. Can I set another, customized, CGlogalCursorManager ?
    4. Other possibilities ?
    Thanks in advance for all those responding.

    I think you mean that I can override the validate method for each custom UI object separately.
    That's a possibility, but I was looking for a more general solution. If possible, I would to extends one
    class. E.g. can I set another event queue ? That way, I could make a custom event queue in case of a Mac OS browser.

Maybe you are looking for

  • I cannot set up iCloud but it's linked to an old email addy which I can no longer access.  Any suggestions?  Thanks

    Just got 4s & I'm attempting to set up iCloud.  Settings, iCloud - Account Not Verified.  Messages states to check my email for instructions to verify .... but the email address listed no longer exists.  Any suggestions?

  • Java Web start and CR

    <p>Has anyone been able to use CR with Java Web Start? If so, please share your experiences. I have not been able to find any info on this. I guess the most fundemental question is if CR supports the web start model.</p><p> Thanks,</p><p> FR <br /></

  • HTTP Status 401 error download sdk

    So I guess I'm missing the secret sauce here.   I log  into the portal and click the purple button to download the sdk but all I get is a HTTP Status 401 error: type Status report message description This request requires HTTP authentication (). Same

  • Backup photos to DVD (Not Time Machine)

    Hi, I am running Time Machine and backing up locally. What I am interested in doing is backing up my photos to DVDs and storing the DVDs off site. Is there any easy & free way to do that? I know I can make a burn folder and do it by hand. What I am l

  • Adobe Flash Player not allowed

    When trying to open a video I always get this message 'Adobe Flash Player not allowed". If I right click I get a message saying "allow this plug in". I click that and the video works. Sometimes the right click does nothing, so I cannot view the video