Sharing objects across Tabs of a JTabbedPane

I don't know whether this is an Object-Oriented design question or a JTabbedPane question.
I'm pretty new to Java, so be patient!
I wish to have a JTabbedPane with a tab to do 'Import' of data, and a tab to do 'Export' of data (the SAME data which was imported).
How do I share the data between the 2 tabs? It seems the data belongs at the JFrame level, but then how does the data in each tab access it? In other languages I would pass a reference to the data object in the window to each tab. Or how do I get (or set) the data when the tab changes? And how do I know when the tab changes?
I know if I had one tab with an import/export functionality then I could declare the Collection within that panel.
Help!!!
Thanks ;)

here's a starter
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
class Testing
  int selectedIndex = 0;
  public void buildGUI()
    final JTabbedPane tp = new JTabbedPane();
    tp.setUI(new javax.swing.plaf.metal.MetalTabbedPaneUI(){
      protected void paintTab(Graphics g,int tabPlacement,Rectangle[] rects,int tabIndex,Rectangle iconRect,Rectangle textRect){
        if(tabIndex == selectedIndex) super.paintTab(g,tabPlacement,rects,tabIndex,iconRect,textRect);
    tp.addChangeListener(new ChangeListener(){
      public void stateChanged(ChangeEvent ce){
        selectedIndex = tp.getSelectedIndex();
    for(int x = 0; x < 5; x++) tp.addTab(""+(char)(x+65),new JPanel());
    tp.setPreferredSize(new Dimension(200,200));
    JFrame f = new JFrame();
    f.getContentPane().add(tp);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
}

Similar Messages

  • IE7 shared session across tabs problem

    Hi guys. I am contributing to the development of a system that uses J2EE technologies (struts, hibernate). We have noticed a problem with the recent IE version (IE7) and tabbed browsing. An http session is shared accross the opened tabs, so if a website is accessed through different tabs of the browser, the http session is prone to concurrency issues.
    e.g. a shopping cart will be shared across tabs
    I dont want that. I would prefer each tab to function as a different client (or browser window). Is there any way to overcome this issue? I know struts is prone to this problem, how about other frameworks? thx in advance

    No there is no easy solution in this case. Its not just a struts problem.
    In fact it would affect any application using the servlet "session" scope to store attributes in.
    The session is distinguished by means of a browser session cookie. This cookie is issued to the browser to retain your J2EE session id. It lasts as long as the browser does.
    Maintenance of session cookies is purely the role of the browser. We can't affect it.
    Basically all windows in the same process will use the same "session cookies". ie - popup windows (via links or window.open) share the same session as their parent. This is useful sometimes, and a complete pain at other times.
    If you open a completely seperate IE instance/process it will get its own session cookie and thus maintain a different 'session' than the other window, but tabs all share the same session.
    The only way to do this would be to NOT use cookies to maintain your J2EE session, and instead use urlEncoding to keep track of the J2EE sessionid. ie add ;jsessionid=[sessionid] onto every link (as done by response.encodeURL())
    hope this helps,
    evnafets

  • Sharing object across 2 different web application

    Hello,
         I do not know if this is a right place to ask this kind of question...
         I have two different web applications running on 2 different tomcat servers.
         One of them creates one object ( say myComplexClassObject) which is serializable..
         and I want to share this object in another web applications.
         Both the apps are developed using JSP and servlets.
         Is there any way, I can make this object available in another application ?
         As the request object can not be used across 2 different contexts, I can not set it as attribute on request.
         I tried serializing myComplexClassObject in some test.dat. Problem going by this way is that
         how do I send this file to another application ?
         What I did is as follows....
         In the first app , I created the object and serialized it in one file test.dat. In the same app I read
         test.dat and send the content as query parameter to a JSP in another app. That JSP collects all the query parameters
         and constructs a big string out of it and then writes it to a file, test2.dat and tries to deserialize this.
         File sizes come out to be same. But it gives me StreamCorruptedException.
         Any idea, where I am doing wrong ? or any other way to share this object or to send the file to another app?
         I can not use FTP for some reasons. Size of the test.dat file is more than 10 KB.

    Some possible solutions:
    Use a webservice calls to pass the object,
    Use JAXB to convert the object to XML, pass the XMLover HTTP or a socket and use JAXB to convert the XML back into an object.
    Store the object as a blob in a database.
    Store the object in a Java aware database that can handle Java objects.
    Store the data in the object in a database.
    I am curious as to what information ot functionality is contained in this object that you feel the need to pass it between two servers.

  • JAXB: Shared objects across multiple xsds

    Hi all,
    Have three xsd files which all contain a few shared classes, I use xjc to put each one into a different package, and then of course they're incompatible with each other. I've tried placing all generated code in one package but the object managers aren't created properly. Also tried creating a base class and extending each shared class from there but that didn't work either.
    Does anyone know the best way to do this without manually modifiying the xml?
    Grateful for any help,
    Many thanks,
    Chris.

    That's too bad. Can't you record the update all function, create a batch, and run through all the psd files?
    Btw, the Photoline betas now also include a placeholder layer that instantly updates when the user changes the externally linked file(s). If the file with the externally linked content is open while changing the file(s), Photoline automatically senses the change, and will update accordingly. No need for an update function.
    I wonder if the Photoshop devs could include a similar function for their linked smart objects. It would simplify life.

  • Shared objects across JVMs?

    I'm sure this topic must come up fairly frequently, but try as I might, I couldn't find a satisfying answer for what I'm looking for.
    I have an object that loads a very large in-memory datastructure from disk early in its lifetime, after which time the datastructure is read-only.
    My application runs a number of different JVMs on my machine, and each of these JVMs has to load the same datastructure, wasting time and immense amounts of memory.
    I know I can likely improve the load time by storing a serialized version of the object itself on disk, but that doesn't help with the more serious problem: the memory usage.
    Any suggestions for a good, lightweight way to share this read-only memory across the JVMs?

    dougcook wrote:
    Brynjar wrote:
    One question though, is something preventing you from just using a database to store and serve this structure?Mainly performance. The structure gets accessed an unbelievable number of times inside an already compute-bound bit of code (that takes days to run as it is). That would also be my concern with RMI; you're right, I could serve up individual requests for bits of data (looking much like a database), but then I'd worry that the overhead of RMI would kill me. Thus the hope that I can somehow just share the read-only memory between JVMs.
    Edited by: dougcook on Feb 8, 2009 9:54 AMIf you need fast access to all of the structure in multiple applications concurrently, then I think you're out of luck using RMI as well, or any other socket based communication for that matter, for the same performance reason. How large is this structure and how is is currently loaded? Also, do the applications need to be separate? You would be able to share the memory if they were all running within the same jvm.

  • Sharing objects between different tabs on a JTabbedPane

    Does anyone know how to share objects on different tabs of a JTabbedPane? I.e., I want the same buttons/corporate logo to appear on each tab in the same location, and thus the same functionality, locations, look, etc...
    Currently, if I invoke the add(Component) method for the same component but for different panes, only the pane that had the last add() method called contains the object.
    Thanks,
    adam

    An instance of a GUI component can only be in one place in the GUI (visible or not).
    You could make your own component class (extending JPanel and containing other components you want) and then create an instance of this for each tab.

  • Sharing of Objects across applications

    Hi,
    Is it possible to reference an object initialized by another application?
    For example, I have a Logger object that I instantiated from App1. Then I decided to come up with App2. I want to use in App2, the same logger innstance I am using in App1. Of course, assuming that App1 is running. If not, App2 shall create the Logger object and when App1 is run, App1 now shall reference the Logger object App2 created.
    I guess what I am pointing out here is how sharing of objects across application can happen in Java.

    There is no direct support for this in JVM - you cannot reference object created by JVM#1 from JVM#2 playing fair game =)
    If you need 100% pure JAVA solution the only way to do it is to use
    networking, either RMI (as it was already suggested) or coding your own TCP protocol. Main drawback - it'll be slow.
    For faster access you'll need to use JNI and some sort of interprocess communication method - shared memory/messages/etc. This might be faster (there will be no TCP/IP marshaling) but it'll be more combersome to support it for different OS.

  • TestStand (Shared Object) in show step in variable tab.

    After selecting show step in variable context (tab) during execution, expanding the selected step I see the following, (plus more):  
    +TS (Shared Object)                              Step Type TEinf (Container)
    What does (Shared Object) mean? I posted previously about changing "InBuff" values on the fly. But something has happened to prevent this and I can't figure out what it is but, I think this shared object property has something to do with it.
    From a TestStand surface scatcher.
    thanks

    Shared object means that all of the properties underneath and including that object really just point back to the original version of the properties. In the case of TS, this means they all point back to the edit time version of the step. Changing the properties under TS at runtime is generally something you should avoid doing because you will be editing the actual edit time version of the step. This also has multithreading consequences because shared properties could potentially be accessed by more than one thread at the same time, thus if one thread is modifying them while another thread is accessing them, you can get unpredictable results. The properties under TS are meant to be read-only at runtime.
    Hope this helps explain things,
    -Doug

  • Why server side shared object doesn't work for me ?

    application.onPublish = function (client, p_stream)
         var myInfo = SharedObject.get(p_stream.name);
         myInfo.setProperty("live", true);
    I set the sharedobject using code above,now I can publish video,but so is not set(from admin console, "shared object" tab).
    What can be possible reason for this?

    Change your code to below and see if it works (i mean i am not saying it will work - i am telling you to just try out - if it does not work - i'll look more into details)
    var myInfo;
    application.onPublish = function (client, p_stream)
         myInfo = SharedObject.get(p_stream.name);
         myInfo.setProperty("live", true);

  • How to Hide a Tab in a jTabbedPane

    Hello, I am trying to toggle the Visibility of a tab in a jTabbedPane... I have tried every permutation of these that I could think of:
    myTab1.Visible(False);
    myTab1.Hide();
    myTab1.updateUI();
    myTabControl.doLayout();
    myTabControl.updateUI();
    myTabControl.repaint();
    myTabControl.Layout();What am i missing?
    Please help.

    Its not complicated
    Object myTabls[]=new Object[tabbedPane.getTabCount()];
    this will create an array.
    now
    for (int a=0;a<tabbedPane.getTabCount();a++)
    myTabs[a]=tabbedPane.getComponentAt(a);
    with an array of Components and their placement (index)
    you can do what you want.
    I think Java Merlin (1.4) has a setVisible for a tab, and my guess is that they have implemented that this way.
    You can do it either way.

  • Shared Objects not imported properly

    I am moving from 6i to 9i.
    I exported my 6i applications.
    I imported them into 9i.
    The one application consists of some tables shared from another. I imported the source of the shares first.
    In the RON the shared objects show correctly under the "Table Definitions", but they are absent in the Design Editor under the "Server Model Tab." Trying to reshare them causes an error (as expected).
    How do I reconcile the database so the shared object show up properly ?
    Help appreciated
    Andrew

    Hi Neeraj,
    first if you did not initialize Task's user and it comes back uninitialized that does not sound like a problem.
    Probably the read only User was cached and not explicitly refreshed by subsequent queries. I.e. if User is changed on the database that change won't necessarily get reflected in the toplink cache.
    Try setting descriptor.alwaysRefreshCache(true);

  • Modifying Dependent Shared Objects in Executables

    I am attempting to perform the following operations on ELF32 format files:
    1) modify the names of the NEEDED shared objects that are referenced by an executable after the executable has been built.
    2) modify the embedded SONAME of a shared object file (adding one if it does not exist) after the shared object file has been built.
    3) modifying the NEEDED shared objects that are referenced in a shared object file after it has been built.
    The shared objects and executables are built from third party software that we have the source code for, but we do NOT want to modify the Makefile for each third party package each time we build a new version.
    Of the three items, the one that is proving the most challenging is the modification of the executable files after they have been built.
    Is there either a tool that enables me to modify these fields in the shared objects as well as the executables? Is there a way that I can re-link a shared object or executable file and then specify that modifications be made to the existing SONAME and NEEDED information?
    (I have attempted unsuccessfully to use the elf library on executable files. Even relatively simple operations, such as modifying the length of the dynamic string section in which the NEEDED shared object is stored breaks the executable file.)

    Hello Tomi,
    First, thank you for taking the time to write such a well
    though-out suggestion.  Are you familiar
    with the “LabVIEW Object-Oriented Programming: The Decisions Behind the Design”
    document?  I think the reason we chose to implement a ‘by
    value’ strategy, is that is more in line with the LabVIEW programming paradigm
    of dataflow, and would make sense to most of our LabVIEW users.
    I think your suggestion is interesting, and it does
    highlight the need to think outside of the conventional LabVIEW box and look to
    some of the innovative things other languages do.  However, I think we all agree that
    synchronization takes careful planning and extra work for the programmer.  Even with an ‘ideal’ solution I see no way
    around this.  For LabVIEW users today,
    one great way to get synchronized ‘by reference’ semantics with your objects is
    to use a single-element queue to pass your object.  The queue itself is passed ‘by reference’ and
    is inherently synchronized!  The does
    have the disadvantage of adding one more small layer of complexity to your
    program, but some complexity would have to be introduced in any situation.  The other disadvantage with this is that it
    is not always an intuitive way to implement your program and requires some
    amount of LabVIEW knowledge before one would generally come across this
    technique.
    In any case, I appreciate the time and effort you put in to
    your suggestion.  Please make sure that
    you submit the suggestion formally through the NI Product Suggestion Center so
    that it can be reviewed by some of the decision makers here.
    Thanks again,
    Travis M
    LabVIEW R&D
    National Instruments

  • Shared Objects Propogate

    Hello Friends,
    I am using shared object to share data across users/sessions/applications servers for a particular system and client,when i want to push data from 1 application to all other application servers,i use the method cl_ps_hlp_shm_area propogate,but this is not working,can anyone help me.
    regards
    kaushik

    I've also done the following:
                    private var my_so:SharedObject;
    maybe I also need to make the   my_so.data bindable as well so that the
    following code works as well?
    <mx:Button toolTip="{(my_so.data.wantMusic)?'Turns off music':'Turns on
    music'}"
                   id="musicOn"
                   icon="{(my_so.data.wantMusic)?imgPlayClass:imgPlayOff}"
                    cornerRadius="9" fillAlphas="[1.0, 1.0]"
    fillColors="[#0FEFBD, #7106D5]" width="26">
            <mx:click>
                    <![CDATA[
                        my_so=SharedObject.getLocal("mediaCenter");
                        if (my_so.data.wantMusic)
                            stopIntroSound();
                            my_so.data.wantMusic=false;
                            my_so.flush();
                        else
                            playIntroSound();
                            my_so.data.wantMusic=true;
                            my_so.flush();
                    ]]>
                </mx:click>
        </mx:Button>
    best wishes
    Nikos

  • Sharing Functions Across Applications(containers)

    Can anyone help with a final word on sharing functions between
    applications?
    I have read many conflicting accounts on the ability in 6i to share
    objects across application systems through the use of common functions,
    global process steps, referencing, or shortcuts. Best case scenario, I
    would like to share functions across containers, include these functions
    in multiple process models, and be able to create process flows between
    functions. Is this possible? Is the bug 1787721 which doesn't allow
    common functions across applications a true bug, or is this the new
    functionality in 6i?
    Thanks for the help.

    Hi Cynthia,
    If I understood, you want to know what the steps you need to
    follow to share a object, but before it, you need to know a
    basic new characteristc at the Designer6i.
    The basic characteristc that you must know is that you don't
    share objects to application from other one anymore, you create
    a reference to other objects in another Application from other
    one that already exists. Althoug you must pay attention that you
    can create references to objects between applications when they
    are in the same Workarea.
    It's too simple.
    Put the cursor on the Application that want to create reference
    from a previous existing object. Choose the option "Create
    Reference". Choose the object that you want to reference (Use
    the filter if you want) and than it will be work.
    I hope that I had to help you.
    Regards,
    Marcos Vinmcius B. Xavier
    E-mail : [email protected]

  • How to find name of tab in a JTabbedPane?

    I have some panels added to different tabs in a JTabbedPane. I want to get the name associated to the tab that the user clicks on. I tried a search on the forum but couldn't find anything.
    I have the below method that will tell me when I changed tabs, but what now?
    tabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent event) {
        System.out.println("Changed tabs.");
    });Thanks for any/all help!

    Thank you for your reply. Although I could have done without the smart ass comment, I still appreciate your help!
    For those of you comming across this thread in a search, here is the solution:
    tabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent event) {
        javax.swing.JTabbedPane tab = (javax.swing.JTabbedPane)event.getSource();
        String strTabName = tab.getTitleAt(tab.getSelectedIndex());
        System.out.println(strTabName);
    });

Maybe you are looking for

  • Liquidity Planner - Liquidity Item Re-assignment

    Hello Experts My question is regarding Liquidity Planner. We have offsetting items being allocated to Liquidity Item IN-TFR-000(unallocated payments). For example clearing document 10018475 line item 1 reports +4375.00 for Liquidity item IN-TFR-000.

  • HR custom authorization objects

    Is it possible to have more than one custom HR authorization object active at the same time? For example if I need 2 custom variations of P_ORGINCON (I  have some very complex requirements),  is that possible, or am I limited to just 1? Having more t

  • SetContentType, Header or ??

    Hi, first post so kid gloves please! OS debian sarge tomcat 5.0.19 j2sdk1.4.2_04 I have a minor but irritating problem. I have a servlet which produces a CSV file and prompts to save, and it works OK. The problem is that an unwanted blank browser win

  • How did i solve "Cannot create target element" but still having problems.

    Hi Experts, I solved my problem of "Cannot create target element" by removing of the data type structure the following fields : DT_AS400_1 -> Complex Type Payroll      1..1   (Should i put 0..0?)    ->  Row  0..Unbounded And then Fields to be passed.

  • Again but now in Lion Finder don't show art cover on the songs

    As happened on Snow Leopard and some updated fixed it, now i have the same problem in Lion. I did a clean instalation. Anyone else have the same problem?