Problems sizing multiple JPanels.

I'm writing a survey program that needs to be formatted to a certain size. I'm using calls to panel.setsize( ) to set the size to 800 x 600.
I have nine JPanels as globals, all of which are created and "packed" initially. These JPanels are supposed to display in a global JFrame, one at a time. After each "next button" click I call frame.remove(panel) to remove the current panel and frame.add(panel) to add the next. Then I call pack again.
Everything works fine until looping from the final panel to the first. Upon doing so all of the elements in the JPanel disappear, (although hovering over the invisible elements makes them reappear.)
Is there anything I'm doing wrong?

Well, calling repaint after pack seemed to solve the problem.
Does anyone care to provide insight as to why?
Thanks.

Similar Messages

  • Simple FocusTraversalPolicy (multiple JPanels)

    I've seen quite a few posts on this topic, so I thought I'd share my own simple solution. It solves the problem of the tab order when you have multiple JPanels and want to enforce a specific tab order.
    class MyFocusTraversalPolicy extends FocusTraversalPolicy {
        Vector components;
        public MyFocusTraversalPolicy(Vector components) {
            this.components = components;
        public Component getComponentAfter(Container root, Component comp) {
            int ix = components.indexOf(comp) + 1;
            Component c;
            if(ix >= components.size())
                c = getFirstComponent(root);
            else
                c = (Component)components.get(ix);
            return c.isEnabled() ? c : getComponentAfter(root, c);
        public Component getComponentBefore(Container root, Component comp) {
            int ix = components.indexOf(comp) - 1;
            Component c;
            if(ix < 0)
                c = getLastComponent(root);
            else
                c = (Component)components.get(ix);
            return c.isEnabled() ? c : getComponentBefore(root, c);
        public Component getDefaultComponent(Container root) {
            return (Component)components.get(0);
        public Component getFirstComponent(Container root) {
            return (Component)components.get(0);
        public Component getLastComponent(Container root) {
            return (Component)components.get(components.size() - 1);
    }Create the Swing components as usual, add the components to a vector, in the order you want them to be tabbed:
    Vector comps = new Vector();
    comps.add(textField1);
    comps.add(comoboBox1);
    comps.add(((JSpinner.DefaultEditor)spinner1.getEditor()).getTextField()); 
    MyFocusTraversalPolicy policy = new MyFocusTraversalPolicy(comps);
    setFocusTraversalPolicy(policy);Note how the JSpinner component is added. This works fine with tabbing forwards and backwards; skips disabled components as expected.

    Hi AikoMuto,
    I want to traverse focus among some components(not all the components)
    lie in multiple panels which are in different classes. Following is my
    class structure.
    Class Test extends JPanel{
    PanelA panelA;
    PanelB panelB;
    PanelC panelC;
    public void jbInit()
    Vector comps = new Vector();
    comps.add(panelA.fieldA);
    comps.add(panelB.fieldB);
    for(int i=0;i<panelC.buttons.length;i++){
    comps.add(panelC.buttons);
    MyFocusTraversalPolicy policy = new MyFocusTraversalPolicy(comps);
    setFocusTraversalPolicy(policy);
    Class PanelA extends JPanel{
    JTextField fieldA;
    JScrollbar scrollA;
    Class PanelB extends JPanel{
    JTextField fieldB;
    JScrollbar scrollB;
    Class PanelC extends JPanel{
    JButton[] buttons;
    I want to traverse focus among fieldA -> fieldB -> buttons[0]
    -> buttons[1] -> ................ -> buttons[buttons.length -1].
    I used your code and checked whether it's working for my example. Setting traversal policy is done in parent panel i.e. in Test class. But
    unfortunately it doesn't capture both Tab and Tab+Shift keys. I
    debugged the code and found that it doesn't call either of
    getComponentAfter() or getComponentBefore() methods for above key
    events.
    I guess your code is not working as the panels are in different classes.
    Could you please help me to get this done?
    Thanks & Regards

  • Problem with multiple Toplink/JPA apps in same server

    Anyone have experence of running serveral Toplink/ EJB-3 Web apps in the same server (OC4J, alas)?
    We seem to get a problem with the second app failing to initialise toplink, with an entity not found message. Each app runs OK on it's own.

    Yes, they access the same datasource and most of the tables overlap.
    We're thinking it might help to have common entity classes and put them in a shared library, but I don't know if this is relevant (setting up shared libraries complicates testing and tends to snowball, I reckon we need about 15 jars all told).
    I''ve had some funnies on OC4J before which I think may be to do with it's use of ClassLoaders, for example I initially put persistence.xml in the libary jar with the data model, but for some reason I get the entity not found error that way. It only seems to work if it's in the classes folder.
    For the moment we're getting arround the problem with multiple OC4J instances in the server.

  • How do I add multiple JPanels to a JFrame?

    I've been trying to do my own little side project to just make something for me and my friends. However, I can't get multiple JPanels to display in one JFrame. If I add more than one JPanel, nothing shows up in the frame. I've tried with SpringLayout, FlowLayout, GridBagLayout, and whatever the default layout for JFrames is. Here is the code that's important:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import javax.swing.*;
    public class CharSheetMain {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              CharSheetFrame frame=new CharSheetFrame();
              abilityPanel aPanel=new abilityPanel();
              descripPanel dPanel=new descripPanel();
              frame.setLayout(new FlowLayout());
              abilityScore st=new abilityScore();
              abilityScore de=new abilityScore();
              abilityScore co=new abilityScore();
              abilityScore in=new abilityScore();
              abilityScore wi=new abilityScore();
              abilityScore ch=new abilityScore();
              frame.add(aPanel);
              frame.add(dPanel);
              frame.validate();
              frame.repaint();
              frame.pack();
              frame.setVisible(true);
    }aPanel and dPanel both extend JPanel. frame extends JFrame. I can get either aPanel or dPanel to show up, but not both at the same time. Can someone tell me what I'm doing wrong?

    In the future, Swing related questions should be posted in the Swing forum.
    You need to read up on [How to Use Layout Managers|http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]. The tutorial has working example of how to use each layout manager.
    By default the content pane of the frame uses a BorderLayout.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
    The code you posted in NOT a SSCCE, since we don't have access to any of your custom classes. To do simple tests of adding a panel to frame then just create a panel, give it a preferred size and give each panel a different background color so you can see how it works with your choosen layout manager.

  • Problem in multiple selections in a jList

    I have two jLists. Now I have to select some items from one jlist and have to transfer in the other one. But while trying to do it in the runtime I am getting some unexpected runtime errors including "Exception occurred during event dispatching". When I try to transfer only one item it works fine but shows problem in multiple selections. Pleast give your suggestions.

    [_First suggestion_|http://catb.org/~esr/faqs/smart-questions.html]
    [_Second suggestion_|http://mindprod.com/jgloss/sscce.html]
    db

  • Problem Using Multiple With Statements

    I'm having a problem using multiple WITH statements. Oracle seems to be expecting a SELECT statement after the first one. I need two in order to reference stuff from the second one in another query.
    Here's my code:
    <code>
    WITH calculate_terms AS (SELECT robinst_current_term_code,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
    END first_term,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
    END second_term
    FROM robinst
    WHERE robinst_aidy_code = :aidy)
    /*Use terms from calculate_terms to generate attendance periods*/
    WITH gen_attn_terms AS
    SELECT
    CASE
    WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
    WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
    END first_attn_period,
    CASE
    WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
    WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
    END second_attn_period
    FROM calculate_terms
    SELECT *
    FROM gen_attn_terms
    <code>
    I get ORA-00928: missing SELECT keyword error. What could be the problem?

    You can just separate them with a comma:
    WITH calculate_terms AS (SELECT robinst_current_term_code,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '40'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '100'
    END first_term,
    CASE
    WHEN robinst_current_term_code LIKE '%60' THEN robinst_current_term_code - '100'
    WHEN robinst_current_term_code LIKE '%20' THEN robinst_current_term_code - '160'
    END second_term
    FROM robinst
    WHERE robinst_aidy_code = :aidy),
    /*Use terms from calculate_terms to generate attendance periods*/
    gen_attn_terms AS
    SELECT
    CASE
    WHEN first_term LIKE '%60' THEN 'Fall '||substr(first_term,0,4)
    WHEN first_term LIKE '%20' THEN 'Spring '||substr(first_term,0,4)
    END first_attn_period,
    CASE
    WHEN second_term LIKE '%60' THEN 'Fall '||substr(second_term,0,4)
    WHEN second_term LIKE '%20' THEN 'Spring '||substr(second_term,0,4)
    END second_attn_period
    FROM calculate_terms
    )Not tested because there are no scripts.

  • Problem using multiple contexts in same thread

    Hello,
    I am having problem using multiple contexts in the same thread. Here is the scenario:
    front-end is calling a ejb1 with a user1 and password. Ejb1 is then calling ejb2
    using user2 and password. I am getting security exception when calling ejb2 with
    the message user1 is not authorized. Looking at the documentation, context 2 should
    be pushed on stack on top of context 1 and context 2 should then be used until
    context.close() is called. It looks like this is not the case in this scenario?
    Regards,
    Jeba Bhaskaran

    I have the GTX670. So pretty much the same.
    When I go to  Edit>Preferences>Playback I see:
    When I select the monitor I am not currently using for Premiere Pro, the Program Monitor shows up full size at 1920X1080 in that monitor.
    While that may not help you, at least you know a similar card can do the job and you know that it should work.. What happens if you drop down to two monitors? Will it work then?
    Also, have you performed the hack that allows Premiere Pro to use the card since that card is not in the file? I have no idea if that is relevant at all, by the way. It is just an attempt at getting our systems to work the same way.

  • Problems printing multiple copies on 1 page in iPhoto version 9.5.1

    I'm having problems printing multiple copies of a photo in my version of iPhoto 9.5.1. I've tried looking at the answers given in Macworld forums for iPhoto '09 but I can't follow them as they refer to clicking 'preferences' - but this button isn't displayed on the 'print' page. Is my version iPhoto '09 or '11?

    iPhoto 9.5.1 is the most recent version of iPhoto '11, as part of the iLife '11 suit of applications.  The printing dialog changed between iPhoto '09 and iPhoto '11.
    The easiest way to print multiple copies of the same photo on one page is to simply duplicate your photo (from the "Photos" menu:  "Photos > Duplicate" and then to select all copies at once and use "File > Print":
    Then select a template and press the "Print" button.

  • Problem deleting multiple keywords in lightroom 5

    I am importing about 20,000 pictures from Flickr. they are all creative commons, and the end result will be the use of approximately 4000 of these in an online sign language dictionary.
    I use Bulkr to import them and this process imports the tags as well as other information such as the photographers name and url.  Many of these photos arrive with hundreds of tags, so that the total number of tags might be 20000 or more.  I need to assign my own tags and delete all the tags that the photo arrived with.  I use the lightroom batch delete to do this (the little minus sign at the top of the keyword list).  i select a keyword, hold down the shift key and scroll down.  the problem is that i cannot just scroll down to the bottom of the list.  There appear to be unpredictable keywords that cause the shift-select process not to work.  if i scroll back up and then carefully scroll part of the way back down, then there will be a point at which shift-select stops working and above that it works. 
    The end result of this is that it takes numerous shift-select-scroll down-select to delete everything so that what should take maybe 2 minutes takes 20 minutes or more. 
    The problem may be related to foreign language keywords especially chinese characters, but even what looks like a perfectly ordinary keyword can stop it.  Two recent examples: travellers cheque  and Київ. In all cases, the words can be deleted when i click directly on them.  you just cant shift-select THROUGH them.
    A separate annoyance that i will just grumble about is that i was forced to put these pictures in a separate catalog because there is always the risk that i could manage to delete my own keywords while batch-deleting everyone elses, and there is no simple way that i know of to undo this. with the separate catalog at least i wont delete all the keywords for my own pictures.

    With respect to problems deleting multiple keywords: On Windows, since at least version 3, LR has had basic bugs when you have more than about 1600 keywords showing.  (Hard to believe it isn't fixed by now.)   A simple workaround for you situation is to filter the keywords one letter at a time and then select the subset of keywords that are showing -- e.g. filter all keywords with the letter "t", then all keywords with the letter "b", etc.
    With respect to not getting the keywords into your catalog in the first place: You can define a Metadata Preset that will clear the keywords on import:

  • Problem with multiple versions of documents being published with 001, 002, etc.

    I am using Contribute CS3. I am having a problem with multiple versions of documents being published on the sever with 001, 002, etc in the name. So that I end up with 2 or 3 versions of a document on the server. Does anyone know why / how Contribute  is doing this? Thanks for any help you can give.

    Your Web site administrator will need to update your key to allow you to delete files you are able to edit.

  • Multiple JPanels on top of each all receiving mouse events

    I have multiple JPanels that are painted on top of each other. Each one has mouse listeners that listen for mouse enters, exits, etc. However, it appears that Swing is only propagating the mouse events for the most visible panel (the one that is on top of all of the others). Is there a way to configure Swing in such a way that all JPanels on the screen will get the mouse events, even if they aren't entirely visible on the screen?
    Thanks,
    -- Ryan

    Hi,
    You can implement mouse listener for panel and you can identify buttons in the panel with the mouse event of panel using MouseEvent.getComponentAt(MouseEvent.getPoint()) instanceof JButton or not.
    I hope this will help,
    Kishore.

  • Problems with multiple idocs in one file ( Inbound file )

    HI,
    Thanks in Advance for your suggestions.. Highly appreciated.
    We have problems with multiple IDocs in one file.
    We are using XIB ( Amtrix ) as Middleware to receive the files.
    Curretenly When the file contains one IDoc then there is no problem. IDoc is created and everything is ok.
    If file contains two IDocs ( for example two messages ORDERS and DELVERY ) then it is creating two IDocs but both IDocs contains ORDERS plus DELIVERY segements information. That is the problem. Some how SAP unable to differentiate the IDocs in the file.. But it knows that how many idocs are there in the file..because it is creating exact number of idocs.
    We are using TRFC port ... Do I need to change it to File port..
    When we have more than one idoc do we need set any parameter in the file ...

    Thanks for the swift response. Always ideas are useful.
    As of now , Middleware cannot split the file.
    Thing is SAP is creating two Idocs with different message types. Problem is First IDoc contains ORDERS message type but also DELIVERY segments as well. Second IDoc with DELIVERY message tyoe but ORDERS segments as well... This is the problem... I think we are missing some field activation in file for EDIDC record.
    As far as I know file port supports the number of IDocs in one file.. Hope TRFC port also supports that

  • Problem deleting multiple rejected photos in Lightroom 3

    I had some frustrating trouble deleting a set of rejected photos. I am running LR3 on Windows 7 64 bit.
    I flagged about 220 out of 600 photos as rejects in a folder. When I hit ctrl-backspace to delete them, the rejects were shown in the grid view but were not deleted. Nothing I could do would delete them, I tried all the workarounds I could find in the forum and tried everything else I could think of. I was able to delete them one at a time but not all at once.
    Then I tried deleting them in chunks... two at a time, three at a time - worked. Then I tried 30 or so - got a message that one or more of the photos had been published to flickr. I clicked OK to delete from Flickr, that was processed then I got the prompt to delete them - worked. Then I tried deleting the rest of the pictures - about 160 left at that point, worked fine.
    There seem to be quite a few people having trouble deleting rejected photos, maybe there is some kind of conflict between the publishing function and deleting rejects?

    With respect to problems deleting multiple keywords: On Windows, since at least version 3, LR has had basic bugs when you have more than about 1600 keywords showing.  (Hard to believe it isn't fixed by now.)   A simple workaround for you situation is to filter the keywords one letter at a time and then select the subset of keywords that are showing -- e.g. filter all keywords with the letter "t", then all keywords with the letter "b", etc.
    With respect to not getting the keywords into your catalog in the first place: You can define a Metadata Preset that will clear the keywords on import:

  • Problem opening multiple pictures in Photoshop

    Problem opening multiple pictures in Photoshop.  OldBob1957 has given me some suggestions on how to overcome this problem.  I tried to Edit.Purge>All, Reset Preferences, Delete the Adobe Photoshop x Prefs.psp folders and Ctrl+Alt+Shift on Photoshop startup.  Did not work, what next?  Delete all the PSP folders.?  There are 45 more in my computer.  Any help will be appreciated.

    Hi Noel:
    I reset the max memory to the high side as suggested but the results when I opened the pictures and changed them was the same.  I could open four but nto the fifth one.
    Lyndon
    PS:  In the event you haven't seen the start of the problem, I thought I would include it here:
      I am working on a picture file, jpegs, changing the size, the level, etc. I open several pictures usually
    3 or 4 and when I try to open the next I receive a pop up error message that says: "Could not
    complete your request because of a program error.” This has just started to happen recently,
    probably since I upgraded to CS6. Previously I could work on a file and have 100 or so pictures
    open and still be able to open additional pictures. I have downloaded and in installed all available
    updates and the message I receive when I check for updates is: “Your applications are up-to-date
    as checked less than a minute ago.” I tried to Edit>Purge>All, Reset Preferences, Deleted the
    Adobe Photoshop Ver. 6 Prefs.psp folder and pressed Ctrl+Alt+Shift on Photoshop startup and
    deleted Adobe Photoshop Settings file. Did not work, what next? Delete all the PSP folders? There
    are 45 more in my computer. Any help will be appreciated.
    LR

  • Resolution problem when printing JPanel with picture on bg

    Hellow!
    I have some problems with printing JPanel component. I have a picture drawn on the background of the JPanel and several buttons on it. The whole JPanel is about 1600x800px. When i print whole the component with the help of PDF virtual printer, component is printed larger than A4 list. It is strange for me because print resolution is 600 dpi, so whole component must be a rectangle with the size about 2.5x1.5 inches. When I scale the graphics before painting component to fit image to page (i mean ... {color:#ff0000}g2d.scale(sc,sc); panel.paintAll(g2d);{color} ...), the picture's quality becomes very bad.
    I understod it so: I draw the component on the paper in screen resolution, then I decrease image size, so quality also decreases.
    My question is: how to draw on the graphics of printing paper the component in printers resolution (600dpi), but not in screen resolution.

    Hi there,
    Could you provide the community with a little more information to help narrow troubleshooting? What operating system?
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

Maybe you are looking for