JPanel not resizing BorderLayout.CENTER component

I have a JPanel (panel_1) with a BorderLayout. In response to a mous event, I want to replace the component at BorderLayout.CENTER. I'm tracking which component is currently there, so when i get the event, I remove the component currently there, and then add a different one using add(component, BorderLayout.CENTER), and then for good measure I call getLayout().layoutContainer(this) (where "this" is panel_1). At this point, I've got another JPanel, panel_2, in the CENTER position of PANEL_1, and I can see that it's been resized correctly. However, panel_2 also has a BorderLayout, and has a JScrollPane in it's CENTER position. adding panel_2 to panel_1 at center, and redoing the layout, doesn't resize the ScrollPane inside panel_2, even though panel_2 itself is resized.
Furthermore, in panel_2, I tried overloading setSize(int, int), setSize(Dimension), resize(int, int), resize(Dimension), and even reshape(int, int, int, int), and none of them got called during the layout, but it's size still comes out different on the other side of the layout.
Can anyone suggest a good way to automatically resize the JScrollPane when the parent container (panel_2) is resized? Is this normal behvior? I thought that BorderLayout was supposed to do this automatically?
Message was edited by:
B.Mearns

LayoutManagers uses the preferredSize to help layout components. The size means nothing, so using setSize() will not help. You should be using setPreferredSize(...).
You may also want to look at using a [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Card Layout which is designed to flip back and forth between multiple panels in the same container.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • Unable to set JPanel size in BorderLayout.CENTER

    I have a class that defines a GUI for a paint-type program. This class extends JPanel. Within the class, I add a JMenu, a vertical JToolbar to the WEST, a JPanel to the SOUTH and lastly, I add the JPanel that the user draws on in the CENTER.
    From my understanding of the BorderLayout, the CENTER object will take up the remaining available space. The program is run from an applet (which has a setPreferredSize() but it does not seem to affect anything - I think b/c the size specified for the applet in the HTML override it). Anyway, when I set the size of the applet in the HTML, the JPanel in the SOUTH gets cut off. In order to fit it, I have to make the size of the applet bigger - but that makes my CENTER JPanel too big. I need the CENTER JPanel to be a certain size b/c I'm saving the image - which needs to be a certain size.
    I do not understand why the JPanel SOUTH is getting cut off. The JToolBar on the WEST is not that big that it should be governing the size, rather it seems like that JPanel in the CENTER is. I've tried setPreferredSize() and setSize() for that CENTER JPanel, but neither of them seem to help.
    I'll appreciate any thoughts/suggestions - I can elaborate or send code if needed. Thank you all in advance.

    Try using setMinimumSize() and setPreferredSize() for all the other components in the frame other than the CENTER Jpanel. For example, if you want you applet to be 300 pixel high by 500 pixels wide, and you want the centre panel to be 200 x 400 pixels, set the other components as follows:
    Dimension westPanelSize = new Dimension(100, 300)); // width x height
    westPanel.setMinimumSize(westPanelSize);
    westPanel.setPreferredSize(westPanelSize);

    Dimension southPanelSize = new Dimension(500, 100)); // width x height
    southPanel.setMinimumSize(southPanelSize);
    southPanel.setPreferredSize(southPanelSize);Good Luck!
    - David

  • Page not resizing from center

    This is really stumping me. Whenever I change the page size from the document setup, it always resizes from the center. Now, randomly, it will resize from somewhere besides center like bottom right or top left.
    The only way around this that I have found is to resize each page with the Page Tool then resize my document.
    What am I missing?
    CS 6 8.0.1
    iMac Snow Leopard

    That's not a feature I've tested before. Using Page Setup does appear to center pages when I enlarge page sizes (e.g., from Letter to Tabloid).
    However, using the Page tool with the Liquid Layout rule Re-Center selected should do the same thing. Just use the Pages panel to select all the pages you want to change. That could be more reliable because it was specifically designed to do that.

  • Jpanel, resize, borderlayout, browser, applet

    Sorry i cant find a good topic for my problem. :) I have an applet with a borderlayout, each time the browser is resize, my applet component is resize too , its ok, BUT i need to put a maximum size for my JPanel (in "Center"), is there a way to change the way that the automatic resize works? I explain why, i have a JPanel, the center one, that have a picture draw on it, when the view area of the JPanel is tiner than the size of the image, i put scrollbar, but i dont want to have the view area bigger than the picture..
    so is there a way
    sorry another time, when i have something long to explain in english, it could be not understandable :)
    thx a lot in advance

    try this, maybe works as you want,
    here component is you JPanel;
    Component component = new Component(){
    public Dimensin getMaximumSize()
    return new Dimension( 100, 100 ); // your picture size
    and as this you can overwrite
    getMinimumSize() and getPreferredSize() methods,
    Sorry i cant find a good topic for my problem. :) I
    have an applet with a borderlayout, each time the
    browser is resize, my applet component is resize too ,
    its ok, BUT i need to put a maximum size for my JPanel
    (in "Center"), is there a way to change the way that
    the automatic resize works? I explain why, i have a
    JPanel, the center one, that have a picture draw on
    it, when the view area of the JPanel is tiner than the
    size of the image, i put scrollbar, but i dont want to
    have the view area bigger than the picture..
    so is there a way
    sorry another time, when i have something long to
    explain in english, it could be not understandable :)
    thx a lot in advance

  • JPanel not registering resize

    Hello, I have several JPanels laid out with BorderLayout. The CENTER panel contains two JPanels with some custom painting in them. These two panels are laid out with GridLayout. When the user clicks on a button a label gets added to the SOUTH panel of the GridLayout causing it to grow larger and the CENTER panel to shrink. When this happens a call is made to resize the custom drawing in the two panels in the CENTER panel. When I call getWidth() and getHeight() it returns the old size of the panels instead of the new smaller size. When I click on the corner of the window like I would if I wanted to resize the whole thing getWidth() and getHeight() return the correct sizes and the custom painting is drawn correctly. Here is the code in question:
    from the JFrame (extends ComponentListener)
    public void componentResized(ComponentEvent e)
      reSizeGraphs();
    public void componentHidden(ComponentEvent e)
    public void componentMoved(ComponentEvent e)
    public void componentShown(ComponentEvent e)
    public void reSizeGraphs() // gets called when the CENTER JPanel is resized
      pop1_graph.reSize();
      pop2_graph.reSize();
    }pop1_graph and pop2_graph are the two JPanels in the CENTER JPanel of the BorderLayout.
    Here is the code in the pop_graphs:
    public void reSize()
      width  = getWidth();
      height = getHeight();
      repaint();

    make sure your
    public void reSize() {
    width = getWidth();
    height = getHeight();
    repaint();
    ask the real panel size, not the JFrame size.
    it seems your getWidth and getHeight always get the JFrame size.
    try more specific like panel1.getWidth() and panel1.getHeight()
    I quickly dvlp a test program, every thing works correctly,
    that may not swing problem, there are some bug in your code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
      JButton b = new JButton("Click to add label");
      JPanel p1 = new JPanel();
      JPanel p2 = new JPanel();
      JPanel center = new JPanel(new GridLayout(1,2));
      JLabel label = new JLabel("Add to change the size");
      boolean added = false;
      public Test() {
        center.add(p1);
        center.add(p2);
        getContentPane().add(b, BorderLayout.WEST);
        getContentPane().add(center, BorderLayout.CENTER);
        p1.add(new JButton("anything"));
        p2.add(new JButton("anything"));
        p1.setBorder(BorderFactory.createLineBorder(Color.red, 2));
        p2.setBorder(BorderFactory.createLineBorder(Color.green, 2));
        //pack();
        setSize(400, 200);
        System.out.println("p1: width=" + getWidth()+ ", height=" + getHeight());  
        System.out.println("p2: width=" + getWidth()+ ", height=" + getHeight());
        p1.addComponentListener(new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            System.out.println("p1: width=" + p1.getWidth()+
                               ", height=" + p1.getHeight());
        p2.addComponentListener(new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            System.out.println("p2: width=" + p2.getWidth()+
                               ", height=" + p2.getHeight());
        b.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (added) { getContentPane().remove(label); }
            else { getContentPane().add(label, BorderLayout.SOUTH); }
            added = !added;
            validate();
      public static void main(String[] args) {
        JFrame f = new Test();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }

  • Adding and displaying a new JPanel -- not working as expected

    I'm starting my own new thread that is based on a problem discussed in another person's thread that can be found here in the New to Java forum titled "ActionListener:
    http://forum.java.sun.com/thread.jspa?threadID=5207301
    What I want to do: press a button which adds a new panel into another panel (the parentPane), and display the changes. The Actionlistener-derived class (AddPaneAction) for the button is in it's own file (it's not an internal class), and I pass a reference to the parentPane in the AddPaneAction's constructor as a parameter argument.
    What works: After the button is clicked the AddPaneAction's actionPerformed method is called without problem.
    What doesn't work: The new JPanel (called bluePanel) is not displayed as I thought it would be after I call
            parentPane.revalidate();  // this doesn't work
            parentPane.repaint(); 
    What also doesn't work: So I obtained a reference to the main app's JFrame (I called it myFrame) by recursively calling component.getParent( ), no problem there, and then tried (and failed to show the bluePanel with) this:
            myFrame.invalidate();  // I tried this with and without calling this method here
            myFrame.validate();  // I tried this with and without calling this method here
            myFrame.repaint();
    What finally works but confuses me: I got it to work but only after calling this:
            myFrame.pack(); 
            myFrame.repaint();But I didn't think that I needed to call pack to display the panel. So, what am I doing wrong? Why are my expectations not correct? Here's my complete code/SSCCE below. Many thanks in advance.
    Pete
    The ParentPane class:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class ParentPane extends JPanel
        private JButton addPaneBtn = new JButton("Add new Pane");
        public ParentPane()
            super();
            setLayout(new BorderLayout());
            setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            setBackground(Color.yellow);
            JPanel northPane = new JPanel();
            northPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            northPane.setBackground(Color.yellow);
            northPane.add(addPaneBtn);
            add(northPane, BorderLayout.NORTH);
            // add our actionlistener object and pass it a reference
            // to the main class which happens to be a JPanel (this)
            addPaneBtn.addActionListener(new AddPaneAction(this));
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
        private static void createAndShowGUI()
            JFrame frame = new JFrame("test add panel");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new ParentPane());
            frame.pack();
            frame.setVisible(true);
    } the AddPaneAction class:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    public class AddPaneAction implements ActionListener
        private JPanel parentPane;
        private JFrame myFrame;
        public AddPaneAction(JPanel parentPane)
            this.parentPane = parentPane;
         * recursively get the JFrame that holds the parentPane panel.
        private JFrame getJFrame(Component comp)
            Component parentComponent = comp.getParent();
            if (parentComponent instanceof JFrame)
                return (JFrame)parentComponent;
            else
                return getJFrame(parentComponent);
        public void actionPerformed(ActionEvent arg0)
            JPanel bluePanel = new JPanel(new BorderLayout());
            bluePanel.setBackground(Color.blue);
            bluePanel.setPreferredSize(new Dimension(400, 300));
            JLabel myLabel = new JLabel("blue panel label");
            myLabel.setForeground(Color.LIGHT_GRAY);
            myLabel.setVerticalAlignment(SwingConstants.CENTER);
            myLabel.setHorizontalAlignment(SwingConstants.CENTER);
            bluePanel.add(myLabel, BorderLayout.CENTER);
            parentPane.add(bluePanel);
            myFrame = getJFrame(parentPane);
            //parentPane.revalidate();  // this doesn't work
            //parentPane.repaint(); 
            //myFrame.invalidate(); // and also this doesn't work
            //myFrame.validate();
            //myFrame.repaint();
            myFrame.pack();  // but this does!?
            myFrame.repaint();
    }

    For me (as it happens I'm using JDK 1.5.0_04) your code appears to work fine.
    It may be that we're seeing the same thing but interpreting it differently.
    1. When I run your application with your "working" code, and press the button then the JFrame resizes and the blue area appears.
    2. When I run your application with your "not working" code and press the button then the JFrame does not resize. If I manually resize it then the blue area is there.
    3. When I run your application with your "not working" code, resize it first and then press the button then the JFrame then the blue area is there.
    I interpret all of this as correct behaviour.
    Is this what you are seeing too?
    Are you expecting revalidate, repaint, invalidate or validate to resize your JFrame? I do not.
    As an aside, I do remember having problems with this kind of thing in earlier JVMs (e.g. various 1.2 and 1.3), but I haven't used it enough recently to know if your code would manifest one of the previous problems or not. Also I don't know if they've fixed any stuff in this area.

  • JPanel not extending to full size of JFrame

    Hello,
    I have a JFrame that represents the launch of my application. The frame is sized for a Welcome message and a subsequent login. Once login has occurred, I have resized the JFrame to fit the application. The frame resizes, but the panels within the frame do not change. I am using revalidate() to update the panel, which works fine for the contents, but, again, the size of the panel if the original size of the panel from the previous frame size. I am at a loss at this point as to how I get past this issue.

    I don't understand what you mean? Also, when I use pack(), my login button, which should appear as south in pane1, appears next to my label in the west.
    Here is some code:
    private JFrame frame = new JFrame();
    private JPanel panel = new JPanel();
    ERPLaunch2()
         // Setup Application Frame
         super("The New Unison ERP System");
         setBounds(280,220,500, 350);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
         // Setup Application Panel
         panel.setLayout(new BorderLayout());
         // Setup Application Pane 1
         pane1.add(cpane1, BorderLayout.CENTER);
         pane1.add(spane1, BorderLayout.SOUTH);
         cpane1.setLayout(new FlowLayout());
         spane1.setLayout(new FlowLayout());
         cpane1.add(welcomelbl);
         spane1.add(loginbtn);
         // Setup Application Pane 2
         pane2.add(cpane2);
         pane2.add(spane2);
         cpane2.setLayout(new BorderLayout());
         cpane2.add(gpane2, BorderLayout.CENTER);
         spane2.setLayout(new BorderLayout());
         spane2.add(fpane2, BorderLayout.SOUTH);
         gpane2.setLayout(new GridLayout(2,2));
         gpane2.add(new JLabel("<html>User Name: <P>"));
         gpane2.add(uname);
         gpane2.add(new JLabel("<html><P>Password: "));
         gpane2.add(upasswd);
         fpane2.add(okbtn);
         fpane2.add(cancelbtn);
         // Setup Application Pane 3
         pane3.setLayout(new BorderLayout());
         pane3.add(tpane3, BorderLayout.NORTH);
         pane3.add(cpane3, BorderLayout.CENTER);
         pane3.add(bpane3, BorderLayout.SOUTH);
         cpane3.add(sppane3);
         sppane3.setLayout(new GridLayout(1,1));
         tpane3.setLayout(new FlowLayout(FlowLayout.RIGHT));
         sppane3.add(rpane3, BorderLayout.CENTER);
         tpane3.add(logoutbtn);
         bpane3.add(label3);
         rpane3.add(tbpane3);
         // Populate tbpane3 in rpane3 of pane 3
         populateTabbedPane();                    
         // Setup Default Panel as Pane 1 and add to Frame
         panel.add(statusBar, BorderLayout.SOUTH);
         panel.add(pane1);
         getContentPane().add(panel);
         loginbtn.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
              panel.remove(pane1);
              panel.add(pane2);
              panel.revalidate();
         okbtn.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
              //setBounds(280,220,500, 350);
              setSize(500,350);
              frame.pack();
              frame.show();
              //panel.repaint();
              panel.remove(pane2);
              panel.add(pane3);
              panel.repaint();
              panel.revalidate();
         cancelbtn.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
              System.exit(0);
         logoutbtn.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
              System.exit(0);
    public static void main(String args[])
         ERPLaunch2 frame = new ERPLaunch2();
         frame.setSize(275,350);
         frame.pack();
         frame.show();
    }

  • Adding Components to a JPanel not working correctly

    I'm trying to build a JFrame that contains a parent JPanel that will hold a JPanel used to display a message view, a vertical strut and a JPanel that holds VCR-like buttons to cycle through the messages.
    My parent JPanel uses a BorderLayout and the Border is a TitledBorder which tells which product you are viewing (i.e., Message 1 of 5). I build the message JPanel, vertical strut and button JPanel and add them all in order to the parent JPanel which then gets added to the rootContentPane of the JFrame. All that appears is the parent JPanel's TitledBorder, the strut and the button JPanel. Using JSwat, I've been able to determine that the message JPanel has 0 for both its height and width after adding the message components to the JPanel.
    I create the message JPanel with a BorderLayout and an OvalBorder as copied from Manning Press's Swing book (which works fine in other JFrames that I have built), then add other components as necessary to the individual messages (mostly items around the edges with a central display for the actual message). What I can't figure out is why the height and width of the message JPanel isn't growing as I add components.
    I had previously used the same code to display a single message (minus the parent JPanel, strut and button JPanel) where I added the border panels (northPanel, eastPanel, southPanel and westPanel) created in createMsgPanel() directly to the contentPane and it worked perfectly, so I know that the code that adds the message works fine. Then, the requirements changed (go figure) and I had to display multiple messages from the same screen.
    Here's what I've got:
    public class Layout
                 extends JFrame
                 implements ActionListener
       private MissionData missionData;
       private JPanel messagePanel = null;
       private int index = 0;
       private int numMsgs = 0;
       private JPanel mainPanel = null;
       private JPanel buttonPanel = null;
       private TitledBorder titledBorder = null;
       Layout ()
       public Layout (MissionData msn)
          super ();
          missionData = msn;
          setSize (640, 640);
          setIconImage (new ImageIcon ("Icon.jpg").getImage());
          setTitle (((Message) (missionData.messages.elementAt(0))).name);
          numMsgs = missionData.messages.size();
          titledBorder = new TitledBorder (
                            new LineBorder (Color.BLACK),
                            "Message " + String.valueOf (index + 1) +
                            " of " + String.valueOf (numMsgs),
                            TitledBorder.LEFT,
                            TitledBorder.TOP);
          mainPanel = new JPanel ();
          mainPanel.setLayout (new BorderLayout());
          mainPanel.setBorder (new CompoundBorder (titledBorder,
                                                   new EmptyBorder (
                                                      new Insets (3, 3, 3, 3))));
          messagePanel = new JPanel();
          messagePanel.setLayout (new BorderLayout ());
          messagePanel.setBorder (new CompoundBorder (
                                     new EmptyBorder (50, 50, 50, 50),
                                     new OvalBorder (20, 20, Color.white)));
          messagePanel.setBackground (Color.black);
          createButtonPanel ();
          createMsgPanel ((Message) missionData.messages.elementAt (0));
          mainPanel.add (messagePanel);
          mainPanel.add (Box.createVerticalStrut (20));
          mainPanel.add (buttonPanel);
          Container mainContentPane = getContentPane();
          mainContentPane.add (mainPanel);
       private void createMsgPanel (Message msg)
          MessageType msgType = null;
          if (msg.getFunctionalAreaDesignator(0) == Message.GENERAL_INFO)
             if (msg.getMessageNumber(0) == 1)
                msgType = FREE_TEXT;
          else if (msg.getFunctionalAreaDesignator(0) == Message.SUPPORT)
             if (msg.getMessageNumber(0) == 33)
                msgType = CAS;
             else if (msg.getMessageNumber(0) == 34)
                msgType = OSR;
          // Setup NORTH Panel of Display
          JPanel northPanel = new JPanel (new GridLayout (2, 6));
          northPanel.setBackground (Color.black);
          northPanel.add (new JTIMLabel ("", false));
          northPanel.add (new JTIMLabel ("<html>RECV</html>", false));
          if (msgType == CAS)
             northPanel.add (new JTIMLabel ("<html>PCLR</html>", false));
             northPanel.add (new JTIMLabel ("<html>MSN</html>", false));
             northPanel.add (new JTIMLabel ("<html>SAVE</html>", false));
          else if (msgType == OSR)
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
          else if (msgType == FREE_TEXT)
             northPanel.add (new JTIMLabel ("<html>ERASE</html>", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("<html>BRDCST</html>", false));
          northPanel.add (new JTIMLabel ("<html>SEND</html>", false));
          northPanel.add (new JTIMLabel ("", false));
          northPanel.add (new JTIMLabel ("", false));
          if (msgType == CAS)
             northPanel.add (new JTIMLabel ("<html>CAS</html>", false));
          else if (msgType == OSR)
             northPanel.add (new JTIMLabel ("<html>OSR</html>", false));
          else if (msgType == FREE_TEXT)
             northPanel.add (new JTIMLabel ("<html>FTXT</html>", false));
          if (msgType == FREE_TEXT)
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
          else
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("<html>CAS</html>", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
             northPanel.add (new JTIMLabel ("", false));
          messagePanel.add (northPanel, BorderLayout.NORTH);
          // Setup EAST Box of Display
          Box eastBox = new Box (BoxLayout.Y_AXIS);
          if (msgType == CAS)
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("<html>F<br>T<br>X<br>T</html>", false));
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("<html>O<br>S<br>R</html>", false));
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("<html>D<br>P<br>I<br>P</html>", false));
             eastBox.add (Box.createGlue());
          else if (msgType == FREE_TEXT)
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("", false));
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("", false));
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("", false));
             eastBox.add (Box.createGlue());
             eastBox.add (new JTIMLabel ("", false));
             eastBox.add (Box.createGlue());
          eastBox.add (new JTIMLabel ("<html>W<br>L<br>C<br>O</html>", false));
          eastBox.add (Box.createGlue());
          eastBox.add (new JTIMLabel ("<html>C<br>N<br>T<br>C<br>O</html>",
                                        false));
          eastBox.add (Box.createGlue());
          messagePanel.add (eastBox, BorderLayout.EAST);
          // Setup SOUTH Panel of Display
          JPanel southPanel = new JPanel (new GridLayout (2, 5));
          southPanel.setBackground (Color.black);
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("<html>ON</html>", false));
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("", false));
          if (msgType == CAS)
             southPanel.add (new JTIMLabel ("<html>USE</html>", false));
             southPanel.add (new JTIMLabel ("<html>RCALL</html>", false));
          else if ((msgType == OSR) || (msgType == FREE_TEXT))
             southPanel.add (new JTIMLabel ("", false));
             southPanel.add (new JTIMLabel ("", false));
          southPanel.add (new JTIMLabel ("<html>MENU</html>", false));
          southPanel.add (new JTIMLabel ("<html>VMF</html>", false));
          if (msgType == CAS)
             southPanel.add (new JTIMLabel ("<html>NETS</html>", false));
          else if ((msgType == OSR) || (msgType == FREE_TEXT))
             southPanel.add (new JTIMLabel ("<html>CAS</html>", false));
          southPanel.add (new JTIMLabel ("", false));
          messagePanel.add (southPanel, BorderLayout.SOUTH);
          // Setup WEST Box of Display
          JTIMLabel incrLabel = null;
          JTIMLabel decrLabel = null;
          Box westBox = new Box (BoxLayout.Y_AXIS);
          if (msgType == FREE_TEXT)
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("", false));
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("", false));
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("", false));
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("<html>N<br>E<br>X<br>T</html>", false));
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("<html>P<br>R<br>E<br>V</html>", false));
          else
             westBox.add (Box.createGlue());
             westBox.add (new JTIMLabel ("<html>U<br>F<br>C</html>", false));
             westBox.add (Box.createGlue());
             if (msgType == CAS)
                westBox.add (new JTIMLabel ("<html>/\\</html>", false));
                westBox.add (Box.createGlue());
                westBox.add (new JTIMLabel ("<html>\\/</html>", false));
                westBox.add (Box.createGlue());
                incrLabel = new JTIMLabel ("<html>I<br>N<br>C<br>R</html>", false);
                westBox.add (incrLabel);
                westBox.add (Box.createGlue());
                decrLabel = new JTIMLabel ("<html>D<br>E<br>C<br>R</html>", false);
                westBox.add (decrLabel);
                westBox.add (Box.createGlue());
          messagePanel.add (westBox, BorderLayout.WEST);
          // Create CENTER Box to display message bodies
          GriddedPanel centerBox = new GriddedPanel ();
          centerBox.setBackground (Color.black);
          messagePanel.add (centerBox, BorderLayout.CENTER);
          if (msgType == CAS)
             new CASDisplay (msg, centerBox, incrLabel, decrLabel);
          else if (msgType == OSR)
             new OSRDisplay (msg, centerBox);
          else if (msgType == FREE_TEXT)
             new FreeTextDisplay (msg, centerBox);
       private void createButtonPanel ()
          // build the button panel
          buttonPanel = new JPanel ();
          buttonPanel.setLayout (new BoxLayout (buttonPanel, BoxLayout.X_AXIS));
          buttonPanel.setBorder (new LineBorder (Color.BLACK));
          // Create and add the buttons
          buttonPanel.add (createButton ("FIRST_BUTTON"));
          buttonPanel.add (createButton ("PREV_BUTTON"));
          buttonPanel.add (createButton ("NEXT_BUTTON"));
          buttonPanel.add (createButton ("LAST_BUTTON"));
       private JButton createButton (String buttonName)
          JButton button = new JButton ();
          button.addActionListener (this);
          button.setActionCommand (buttonName);
          Image image = null;
          String tooltip = "Press to go to the ";
          if (buttonName.equals ("FIRST_BUTTON"))
             image = new ImageIcon ("firstArrowIcon.gif").getImage();
             tooltip += "First";
          else if (buttonName.equals ("PREV_BUTTON"))
             image = new ImageIcon ("previousArrowIcon.gif").getImage();
             tooltip += "Previous";
          else if (buttonName.equals ("NEXT_BUTTON"))
             image = new ImageIcon ("nextArrowIcon.gif").getImage();
             tooltip += "Next";
          else if (buttonName.equals ("LAST_BUTTON"))
             image = new ImageIcon ("lastArrowIcon.gif").getImage();
             tooltip += "Last";
          tooltip += " message in the lst";
          button.setToolTipText (tooltip);
          button.setIcon (new ImageIcon (image.getScaledInstance (36, 36, Image.SCALE_FAST)));
          return button;
       public void actionPerformed (ActionEvent e)
          if (e.getActionCommand ().equals ("FIRST_BUTTON"))
             index = 0;
          else if (e.getActionCommand ().equals ("PREV_BUTTON"))
             if (index > 0)
                index--;
          else if (e.getActionCommand ().equals ("NEXT_BUTTON"))
             if (index < numMsgs - 1)
                index++;
          else if (e.getActionCommand ().equals ("LAST_BUTTON"))
             index = numMsgs - 1;
          titledBorder.setTitle ("Message " + String.valueOf (index + 1) +
                                 " of " + String.valueOf (numMsgs));
          createMsgPanel ((Message) missionData.messages.elementAt (index));
       private static class MessageType
                            extends EnumeratedType
                            implements Serializable
          final static long serialVersionUID = 1;
          protected MessageType (int value, String desc)
             super (value, desc);
       private static MessageType FREE_TEXT =
          new MessageType (0, "Free Text");
       private static MessageType CAS =
          new MessageType (1, "Call Accounting System");
       private static MessageType OSR =
          new MessageType (2, "Occupational Survey Report");
    }

    That's all well and good, but I've had more times that not where
    people want the entire program, not bits and pieces.Then you missed the whole point of that link.
    We don't want to see bits and pieces of code. We want to see an executable program, but we want an executable program the demonstrates the incorrect behaviour without all the unnecessary code. 90% of the code you posted was not related to your problem. That is we what you do to some basic debugging and remove the parts of code that are not related to the problem so we can concentrate on the code that is related to the problem.

  • Label not resizing

    When I do setText on a Label which I created empty it does not resize correctly so the whole text is not visible. What more should I do to make it resize? myLabel.invalidate() dos nothing to it.
    The Label is added to a Pane which is in its turn added to another Pane which is added to an applet. Thanks for any help!

    I think you should invalidate or validate the Container containing the Label.I do that:
              Container lParent = pComponent.getParent();
              lParent.invalidate();
              lParent.validate();
    It also depends on which LayoutManager you are using and how big that Container is.Take a look at the result here: http://apollo.nu/~ben/sunlabel.jpg
    1. The blue is a panel with borderlayout.
    2. The red and green are two panels with GridLayout(10, 1)
    which are added to the blue panel using:
    add(BorderLayout.WEST, mLabelPanel);
    add(BorderLayout.CENTER, mControlPanel);
    3. The smaller panels with labels are using FlowLayout(FlowLayout.LEFT)
    and added to the red and green panel using:
    add(lPanel)
    In any case it is the LayoutManager of the parent Container that >decides how much space the Label gets, however most LayoutManager will >ask the getPreferredSize() of the Label, which is the space needed to >show it's entire text in it's current font. java.awt.DimensionCould there be a bug in getPreferredSize() for Label in 1.1.8?
    I tried the same with an empty Button for which I set the text later and for that it DOES work using getPreferredSize(), it gets the correct size with either that or my calculation.
    I get the following result for getPreferredSize():
    java.awt.Dimension[width=14,height=23]
    using my own calculation:
    FontMetrics lFontMetrics = getFontMetrics(pComponent.getFont());
    Dimension lStringSize = new Dimension(lFontMetrics.stringWidth(pText), lFontMetrics.getHeight());
    I get this result:
    java.awt.Dimension[width=21,height=15]
    See the marks in the image for 14 and 21. getPreferredSize() obviously gives too little space. The label should say "fr�n" and not "fr�".
    Thanks for your time!

  • Center component frame in VBean area

    I have a component that I want to show in a VBean container area in Forms. All works fine except that the component is not centered in VBean area. It sitts to the right and down a bit outside the bean container. When I add the component to the bean container I do this. Where m_jax is the component being added to the bean area.
    try {
    super.addImpl(m_jax, BorderLayout.CENTER, -1);
    } catch (IllegalArgumentException ex) {
    ex.printStackTrace();
    super.validate();

    Hi Prashant,
    Go to Trans OKKP
    Step 1:Simply double click the COArea which you wanted to configure.
    Step2: In the Assignment Control
    CoCd->CO Area - Change to Cross-Company-Code Cost Accounting
    Note:Only if you change this setting the CoCd Validation will get activated.
    Step 3: Go Back & select the COArea & Double click the Activate components/control indicators
    Step 4:Double click the Fiscal Year in which you wanted to set.
    You can see the CoCd Validation key activated..else you can tick to activate it
    Regards
    Andrew

  • Making components NOT resizable,  forcing certain components to be resized

    Basic setup -
    A maximized JFrame with BorderLayout, a JPanel added to the contentPane in location BorderLayout.WEST, and another container in BorderLayout.EAST (not that it should matter much).
    In the JPanel in the western side, I have it set up with a BoxLayout going down along the Y axis, and in order, I have a JPanel (with a few JLabels inside), a JPanel with a JLayeredPane that uses GridLayout, and a blank JPanel to fill up space (remember, the parent frame is maximized).
    What happens is that my JPanel with the JLayeredPane gets stretched (and distorted) out to the bottom of the frame, when what I want is that the empty JPanel gets stretched and fills up the empty space.
    Is there a way to "lock" the layered pane's size so that it doesn't get stretched? Which layout should I use, or how can I make the JPanel take up the empty space? I suppose I could set the empty panel's preferred height to Integer.MAX_VALUE, but that seems like a rather messy solution.
    Also... sometimes when I click on the JLayeredPane (which is a gridlayout of JPanels) and I remove a component from one of the JPanels, the whole layout gets shifted over and really distorted (not stretched, but jumbled). I've narrowed the problem down to something to do with validation/revalidate. Would anyone happen to have an idea of what's going on?
    Thanks

    I had already tried using glue, but it did nothing so I switched over to the filler JPanel, but that obviously didn't help much, but wonderfully enough, once I set the JPanel with the JLayeredPane to have a FlowLayout instead of a BorderLayout, glue worked!
    So, now that that's over with, anyone have any ideas about the validation issues... like how to prevent things from revalidating, etc...?

  • Error in CK11n - The system could not determine a cost component split for

    Hi All,
    When i run CK11n i have following error:
    The system could not determine a cost component split for the internal activity with activity type 502000 of cost center 10100.
    Procedure
    Check the master data for activity type 502000 of cost center 10100. It is possible that no activity price calculation has been carried out for the cost center.
    could any one give me solution
    Thanking you.

    Well, did you run activity price calculation for the relevant cost center(s)?
    The CCS you're using for product costing (either your COGM split, or the auxillary) has been marked as a "primary" cost component split.  It wants to break secondary costs down into their cost components, and assign those components to components in its own structure.
    Wihout a planned CCS for the activity, this isn't possible.  (This is normally calculated by KSPI during planning.)
    Either calculate an activity CCS is KSPI, assuming that all the prerequisites are in place for that, or uncheck the "primary cost component split" indicator in your costing variant configuration.

  • Group not resizing correctly when contents are moved programmatically

    Hi there,
    My apologies in advance if this is a known issue. I searched the forums but I was unable to find a discussion about this topic. The issue we are running into is when we programmatically move the contents of a Group which is in turn enclosed within a Scroller beyond the Scroller's limits the position of the Group within the stage is incorrectly calculated. This will cause mouseEvents in the area beyond the Group's limits to be "ignored" among other problems.
    I have created an application to illustrate the problem, we are in 4.1:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application
        minWidth="955" minHeight="600"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                private function onGroupClick(event:MouseEvent):void
                    Alert.show("It works");
                private function onButtonClick(event:MouseEvent):void
                    rect.x += 500;
                    rect.y += 500;
            ]]>
        </fx:Script>
        <s:Scroller
            width="100%" height="100%">
            <s:Group id="myGroup"
                width="100%" height="100%"
                click="onGroupClick(event)">
                <s:Rect id="rect"
                    x="0" y="0" width="10" height="10"/>
            </s:Group>
        </s:Scroller>
        <s:Button
            label="Move Rectangle"
            click="onButtonClick(event)"/>
    </s:Application>
    Steps to reproduce:
    Click anywhere in the screen - notice that an alert that reads "It works" shows up.
    Click on the "Move Rectangle" button enough times for the coordinates of the Rectangle to exceed the limits of the Scroller, hence producing scroll bars.
    Scroll all the way to the right and to the bottom.
    Click right next to the right bottom corner - notice that no alert is displayed. The reason is the Group has not resized correctly hence we are actually clicking outside the Group. Resizing your browser window for example will cause the Group to resize and events will again "work". FlexSpy will make things pretty apparent as well.
    Any pointers regarding where this bug lives in the source code or suggestions on how to fix this would be greatly appreciated, this issue is causing us a lot of pain.
    Thanks in advance!!
    ~ TheMadPenguin

    Thanks for logging this in the bugbase: https://bugs.adobe.com/jira/browse/SDK-29112. The latest comments there say:
    Reproduced in 4.0.0, 4.1.0
    Confirmed fixed in 4.5.0.19764
    A workaround for the 4.0.0 and 4.1.0 release would be to put the click handler on the Scroller instead of the viewport.
    Note: This bug seems to be fixed, but the fact that the width/height of  the Group doesn't change is still consistent (and correct).  Group has a  concept of size and content size, scrolling is enabled when the content  size is larger than the size (with Group.clipAndEnableScrolling set to  true which Scroller sets automatically).
    See this spec for more details: http://opensource.adobe.com/wiki/display/flexsdk/Spark+Viewport
    Hans has a good article here: http://hansmuller-flex.blogspot.com/
    Here's a simple example that demonstrates width does not change:
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> 
         <s:Scroller width="100" height="100"> 
             <s:Group id="viewport"> 
                 <s:Rect width="100%" height="100%">
                     <s:fill><s:SolidColor color="red" /></s:fill>
                 </s:Rect>
                 <s:Button id="btn" label="out of view" y="150" click="btn.y += 50" />
             </s:Group> 
         </s:Scroller>
    </s:Application> 
    You might expect that this example should have a red background behind  the Button, but it does not.  That is because width/height of 100% on  the Rect is 100% of the width/height of the viewport, not the  contentWidth/contentHeight.
    One way of getting the behavior where the Rect expands across the whole content size would be to bind to contentHeight:
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> 
         <s:Scroller width="100" height="100"> 
             <s:Group id="viewport"> 
                 <s:Rect width="100%" height="{viewport.contentHeight}">
                     <s:fill><s:SolidColor color="red" /></s:fill>
                 </s:Rect>
                 <s:Button id="btn" label="out of view" y="150" click="btn.y += 50" />
             </s:Group> 
         </s:Scroller>
    </s:Application> 
    Note: You shouldn't specify or change the size of the viewport Group  inside of a Scroller.  The Scroller component manages the size of the  Group in a specific way and if the Group has a size that conflicts with  that then you can get into a bad situation that might cause infinite  loops.  Notice in my example the viewport Group has no size set on it.
    Thanks to SDK QE for the info!
    -Heidi

  • How can I know the size of a JViewport laid out in BorderLayout.CENTER?

    I have a JPanel inside a JScrollPane. The scroll pane is laid out inside of BorderLayout.CENTER. I need to know the size of the JViewport to do stuff like centering and zooming.
    Where can I find the size? All these methods return 0 values for X and Y:
    myScrollPane.getViewport().getSize()
    myScrollPane().getSize()
    myScrollPane.getHorizontalScrollbar().getValue()
    Yes, even the scrollbars won't give me any values! It's all because of the BorderLayout!
    Any ideas? Thanks.

    Sounds like you are accessing the sizes before the views are realized (that is before a call to frame.pack()/show()) They are available only after the layoutManager had a go on it. What is available earlier are preferred/min/max, though.
    Greetings
    Jeanette

  • JPanel not displaying in Windows

    I have a window displaying a panel and some buttons. I installed the application on Solaris and Windows. On Solaris, it displays fine every time. On Widows, it displays the first time I bring up the application but the panel does not display when I close it and bring it back up. Has anyone seen this before. I've put some debugging statements in, but I have no idea where to start looking.
    Thanks,
    Josh

    Here is the code that sets up the panel:
    // Initialize and GUI implementation
    private void jbInit() throws Exception {
    try{
    logger.fine("AudioEditPanel jbInit");
    this.setLayout(new BorderLayout());
    m_audioIcon = new ImageIcon(dataDir + File.separator + m_sAlertIcon);
    TitledBorder curSettingBorder = new TitledBorder(m_sCurSetting);
    TitledBorder soundBorder = new TitledBorder(m_sSound);
    m_editPanel.setLayout(new BorderLayout());
    // Create "Restore Default" button
    m_defaultButton.setText("Restore Default");
    m_defaultButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         defaultButton_actionPerformed(e);
    m_currentPanel.setLayout(new BorderLayout());
    m_currentPanel.setBorder(curSettingBorder);
    m_currentPanel.setPreferredSize(new Dimension(155, 165));
    // Create customized tabel model
    AudioTableModel tableModel = new AudioTableModel();
    curTable = new JTable(tableModel);
    //Set up column sizes.
    initColumnSizes(curTable, tableModel);
    // Only allows single selection
    curTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    curTable.setBorder(BorderFactory.createLoweredBevelBorder());
    curTable.setColumnSelectionAllowed(false);
    curTable.getTableHeader().setReorderingAllowed(false);
    setUpWavEditor(curTable);
    //Fiddle with the Preview column's cell editors/renderers.
    setUpPreviewColumn(curTable.getColumnModel().getColumn(preview_column));
    // Add filter for the File Choose, so only Sound (*.wav) file
    // can be used.
    fc.addChoosableFileFilter(new WavFilter());
    fc.setAcceptAllFileFilterUsed(false);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (m_sDesDir != "") {
    File wav_dir = new File(m_sDesDir);
    fc.setCurrentDirectory(wav_dir);
    fc.setDialogTitle("List of audio files");
    m_assignPanel.setLayout(gridBagLayout1);
    m_assignPanel.setBorder(soundBorder);
    // "Selected Sound" label
    SelectSoundLabel.setFont(new java.awt.Font("Dialog", 0, 10));
    SelectSoundLabel.setForeground(Color.black);
    SelectSoundLabel.setText("Selected Sound:");
    //Click Browse button will pop up file chooser
    browseButton.setActionCommand("Browse");
    browseButton.setText("Browse");
    browseButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         browseButton_actionPerformed(e);
    //Click preview button will play the sound defined in the sound text area
    previewButton.setIcon(m_audioIcon);
    previewButton.setMargin(new Insets(0, 0, 0, 0));
    previewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         previewButton_actionPerformed(e);
    // selected sound text field.
    sSoundText.setBorder(BorderFactory.createLoweredBevelBorder());
    sSoundText.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent e) {
    sSoundText_actionPerformed(e);
    // "Preview" label
    previewTextArea.setFont(new java.awt.Font("Dialog", 0, 10));
    previewTextArea.setText("Preview");
    previewTextArea.setForeground(Color.black);
    // Use GridBag layout to put the components in the proper position
    m_defaultPanel.add(m_defaultButton, BorderLayout.CENTER);
    m_editPanel.add(m_assignPanel, BorderLayout.SOUTH);
    m_assignPanel.add(browseButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 2, 0));
    m_assignPanel.add(previewButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 2));
    m_assignPanel.add(previewTextArea, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    m_assignPanel.add(sSoundText, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 3), 257, 2));
    m_assignPanel.add(SelectSoundLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 0, 6, 0), 6, 0));
    m_curScrollPanel.getViewport().add(curTable, BorderLayout.CENTER);
    m_currentPanel.add(m_curScrollPanel, BorderLayout.CENTER);
    m_currentPanel.add(m_defaultPanel, BorderLayout.SOUTH);
    m_editPanel.add(m_currentPanel, BorderLayout.NORTH);
    m_tabbedPane.addTab(m_sAudioSetting, m_editPanel);
    this.add(m_tabbedPane, BorderLayout.CENTER);
    checkAudioPrefs();
    }catch(Exception e){
    e.printStackTrace();
    System.out.println(e.getMessage());
    }

Maybe you are looking for