JscrollPane, Resize when InternalFrame maximize

Hello all. I have 4 Internal Frames that contain 1 Jtable´s each, and all JTable´s has a JscrollPane. I have the four Internal frames added to a JFrame using GridLayout.. I add code below thats important.
// Create an Desktop For That All Four I-Frame Use
JDesktopPane forInternalFrameDesktop = new JDesktopPane();
// Create an Internal Frame For CustomTable.
JInternalFrame customerFrame = new JInternalFrame("Add Customer To Order",true,false,true,true);
// Create Table For Customer InternalFrame.
customerModel = new DefaultTableModel(customerRow,customerCol);
customerTable = new JTable(customerModel)
customerTable.setOpaque(true);
// Create an ScrollPane for customerTable. 
JScrollPane scroll = new JScrollPane(customerTable);
scroll.set //  ? What will i put here
// Set Size for customFrame
customerFrame.setBounds(0, 0, 500,210);
// Add customFrame to the Desktop.
forInternalFrameDesktop.add(customerFrame);
customerFrame.setVisible(true);
// This is in MainFrame. an Normal JFrame that uses GridLayout To Lay out my Four I-Frames.
GridLayout MstLayout = new GridLayout(0,2);
mstFrame.setLayout(MstLayout);
mstFrame.add(customerIFrame());
mstFrame.add(productInternalFrame());
mstFrame.add(orderReadyInternalFrame());
mstFrame.add(orderDoneInternalFrame());When i maximize any of the four I-Frames, or the main frame i want the ScrollPane to follow. I know there is 1 row command to do that, had it before, but have forgott it. Anyone that has better memory then me?

I use one
JDesktopPane forInternalFrameDesktop = new JDesktopPane();I use four.
private JInternalFrame orderDoneInternalFrame() {
        JInternalFrame orderDone = new JInternalFrame("Order Ready to Send",true,false,true,true);
        JPanel panel = new JPanel();
        orderDoneCol.addElement("Customer ID");
        orderDoneCol.addElement("Product Id");
        orderDoneCol.addElement("Quantity");
        orderDoneModel = new DefaultTableModel(orderDoneRow,orderDoneCol);
        orderDoneTable = new JTable(orderDoneModel);
        orderDoneTable.getTableHeader().setReorderingAllowed(false);
        JScrollPane scroll = new JScrollPane(orderDoneTable);
        orderDone.setBounds(510,320, 500,300);
        orderDone.add(panel);
        panel.add(scroll);
        forInternalFrameDesktop.add(orderDone);
        orderDone.pack();
        orderDone.setVisible(true);
        return orderDone;
    }And one mainFrame holding it all.
public JFrame productFrame() {
        JFrame mstFrame = new JFrame();
        GridLayout MstLayout = new GridLayout(0,2);
        mstFrame.setLayout(MstLayout);
        mstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mstFrame.setSize(1000,700);
        mstFrame.setJMenuBar(openMenu());
        mstFrame.add(customerInternalFrame());
        mstFrame.add(productInternalFrame());
        mstFrame.add(orderReadyInternalFrame());
        mstFrame.add(orderDoneInternalFrame());
        mstFrame.pack();
        mstFrame.setVisible(true);
        return mstFrame;
}Does this make sence to you? Is this the wrong way to handle InternalFrames?

Similar Messages

  • JTextPane inside JScrollPane resizing when updated

    Hiya all,
    I've been struggling with this problem and checking the forums, but didn't find a solution, so I hope someone can help...at least help me for the nice picture :) It has to do with JTextPane's automatically resizing to their content on a GUI update, rather than scrollbars appearing (the desired result).
    Basically, I have a scenario where I am creating a series of multiple choice answers for a question. Each answer consists of a JTextPane inside a JScrollPane, and a JRadioButton, which are all contained in a JPanel (called singleAnswerPanel). So for 2 answers, I would have 2 of these singleAnswerPanels. There is a one large JPanel that contains all the singleAnswerPanels (called allAnswersPanel). This allAnswersPanel is contained in a JScrollPane. Graphically, this looks like:
       |       JPanel (allAnswersPanel) inside a JScrollPane            |
       |                                                                |
       |  ------------------------------------------------------------  |
       | |     JPanel (singleAnswerPanel)                             | |
       | |    ----------------------------------                      | |
       | |   |  JTextPane inside a JScrollPane  |     * JRadioButton  | |
       | |    ----------------------------------                      | |
       | |                                                            | |
       |  ------------------------------------------------------------  |
       |                                                                |
       |                                                                |
       |  ------------------------------------------------------------  |
       | |     JPanel (singleAnswerPanel)                             | |
       | |    ----------------------------------                      | |
       | |   |  JTextPane inside a JScrollPane  |     * JRadioButton  | |
       | |    ----------------------------------                      | |
       | |                                                            | |
       |  ------------------------------------------------------------  |
       |                                                                |
        ----------------------------------------------------------------So above, I show 2 answers that can be filled in with text. So assuming both answer JTextPanes are filled with text beyond their current border (scrollbars appear as expected) and the user wishes to add more answers. I have a button to add another singleAnswerPanel to the containing JPanel (allAnswersPanel), and then I validate the main JScrollPane that contains the allAnswersPanel as it's view. The problem that occurs is the existing single answer JTextPanes resize to the size of their text and the vertical scrollbars (only vertical ones setup) of the JTextPanes dissappear! My intent is to keep the existing JScrollPanes the same size (with their scrollbars) when a new answer is added.
    The code snippet below shows what gets done when a new answer is added:
    private void createAnswer()
        // The panel that will hold the new single answer JTextPane pane
        // (inside a JScrollPane) and radio button.
        JPanel singleAnswerPanel = new JPanel();
        // Create the text pane for the single answer.
        JTextPane singleAnswerTextPane = new JTextPane();
        Dimension dimensions = new Dimension(200, 30);
        singleAnswerTextPane.setPreferredSize(dimensions);
        singleAnswerTextPane.setMaximumSize(dimensions);
        // Create a scroll pane and add the single answer text pane.
        JScrollPane singleAnswerScrollPane =
         new JScrollPane(singleAnswerTextPane);
        // Create a radio button that is associated with the single
        // answer text pane above.
        JRadioButton singleAnswerRadioButton = new JRadioButton();
        // Add the scroll pane and radio button to the panel (for a single
        // answer).
        singleAnswerPanel.add(singleAnswerScrollPane);
        singleAnswerPanel.add(singleAnswerRadioButton);
        // Add the panel holding a single answer to the panel holding
        // all the answers.
        m_allAnswersPanel.add(singleAnswerPanel);
        // Update the display.  m_allAnswersScrollPane is a JScrollPane
        // that has the m_allAnswersPanel (JPanel) as its view.
        m_allAnswersScrollPane.validate();
    }     Sorry for the length of the message, but I really want to solve this problem. So again, when updating the JScrollPane with validate(), the JTextPane for a single answer resizes to it's contents (plain text currently) and loses it's vertical scrollbars, but I want it to stay the same size and maintain the scrollbars.
    Thanks!

    http://java.sun.com/docs/books/tutorial/uiswing/mini/layout.htmlimport javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    public class Test extends JFrame {
        int cnt=0;
        Random r = new Random();
        String[] nouns = {"air","water","men","idjits"};
        JPanel mainPanel = new JPanel(new GridBagLayout());
        JScrollPane mainScroll = new JScrollPane(mainPanel);
        JScrollBar mainScrollBar = mainScroll.getVerticalScrollBar();
        public Test() {
         setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         Container content = getContentPane();
         content.add(new JLabel("QuizMaster 2003"), BorderLayout.NORTH);
         content.add(mainScroll, BorderLayout.CENTER);
         JButton jb = new JButton("New");
         content.add(jb, BorderLayout.SOUTH);
         jb.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae) {
              JPanel questionPanel = new JPanel(new GridBagLayout());
              questionPanel.add(new JLabel("Question "+cnt++),
                   new GridBagConstraints(0,0,1,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.NONE,
                        new Insets(1,2,1,2),0,0));
              questionPanel.add(new JLabel("Why is there "+
                            nouns[r.nextInt(nouns.length)]+"?"),
                   new GridBagConstraints(1,0,1,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.NONE,
                        new Insets(1,2,1,2),0,0));
              JTextArea jta = new JTextArea();
              JScrollPane jsp = new JScrollPane(jta);
              jsp.setPreferredSize(new Dimension(300,50));
              questionPanel.add(jsp, new GridBagConstraints(0,1,2,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.BOTH,
                        new Insets(1,2,1,2),0,0));
              mainPanel.add(questionPanel, new GridBagConstraints(0,cnt,1,1,0.0,0.0,
                            GridBagConstraints.EAST,GridBagConstraints.NONE,
                            new Insets(0,0,0,0),0,0));
              mainPanel.revalidate();
              mainScroll.getViewport().setViewPosition(new Point(0, mainPanel.getHeight()));
         setSize(400,300);
         show();
        public static void main( String args[] ) { new Test(); }
    }

  • Dynamic text resizes when loaded?

    I made sure to set the stage to noScale but I am still having
    a strange problem that is driving my nuts. If I make a static text
    box it will not resizing when I compile and preview or upload the
    swf. However, if I make a dynamic text box, the text size increases
    slightly when i complile the swf. This makes fine tuning the layout
    of web pages extremely difficult because what i see on the stage is
    not the same size as what i see when the swf is complied. Has any
    one else had this problem or know how to solve it because its
    really starting to drive me nuts?

    The only time you should see a size difference is when you
    take text out of a movie clip that has been scaled. Hit Crtl-t to
    get the Transform window and see if the object is %100

  • Do photos get resized when sending from PSE 6 to PE 4?

    Do photos get resized when moving them from PSE 6 to PE4?
    I've come to understand that using overly large photos in slide shows in PE 4 can cause lots of issues, and its recommended to resize photos to 1000x750 (http://www.adobeforums.com/webx/.3bb8822c) before including them in a slide show in PE4. I'm trying to understand the implications of working with photos in PSE 6 and then moving to PE 4 vs. just doing it directly in PE 4.
    I can imagine (at least) two scenarios:
    1. I have all my photos in PE6 and want to work ONLY in PE4. I'm guessing i would resize my photos in the PSE 6 Organizer by using File-->Export and picking a smaller file size (e.g., 1024 x 768) and then import them into PE4 and build my slide show there.
    2. I have all my photos in PSE 6 and want to to create a slide show there and then move it to PE 4 to touch it up or do some fancy stuff to it. Will the photos be resized so PE 4 won't have trouble with them or do i need to resize them in PSE 6, reimport them into PSE 6, build the slide show, and THEN send it to PE 4?

    eric,
    See my post over at http://www.adobeforums.com/webx/.59b85fd0/4
    for reasons why I think that for your current objectives, working in Premiere Elements (rather than making a slide show in PSE) will be a better choice.
    >1. I have all my photos in PE6 and want to work ONLY in PE4. I'm guessing i would resize my photos in the PSE 6 Organizer by using File-->Export and picking a smaller file size (e.g., 1024 x 768) and then import them into PE4 and build my slide show there.
    Yes.
    A couple of considerations
    1- Where will you establish the sequence of the photos in the slide show?
    Are you making an Album in PSE 6 in order to establish the sequence of the slides as you are selecting which photos to use? if YES, we can experiment with sending the photo files in their Album sequence to Premiere Elements.
    Or will you establish the sequence of the photos within Premiere Elements?
    2- When working in Premiere Elements will you be able to do the 600 slides in a single PE project?
    I don't know the answer to this: it will be influenced by your system configuration.

  • Slideshow image resizing when adding new images

    I am creating a series of slideshows on multiple pages. I created one slide show using the "basic" slideshow and resized it to the dimensions and settings I wanted. I have many pictures all of different proportion, therefore, I selected the "fill frame proportionally" so they would all fit the dimension I set. I wanted to use this first slideshow as a template for all of the rest. I added images to this first slideshow with no problems. All of my different sized images scaled or cropped to fit within the dimension I set. The problem comes in when I do two things: 1) When I add other images of different dimensions to this same slideshow gallery, they come smaller that the intended dimensions I set previous. I check the setting and it is still on "fill frame proportionally" similar to the first batch of pictures. 2) The second issue is when copy this slideshow as a template to other pages. When I try to replace or add to the slideshow gallery, the images come in cropped or smaller rather than filling the frame. Again, the settings are still the same from my very first slideshow that worked just as i intended.
    I could resize all the images to all the same dimensions using another program like photoshop, but that is another step that is very tedious and it would seem that it should be something built into Muse.
    Is there a way around this?. Am I doing something wrong? Or is this just one of those glitches that happens with Muse? I appreciate any help that I can get.
    Thanks!

    Hi, I got it to work like this:
    Using background colours in Photoshop so that all sizes are the same in pixels. Then manually adjusting thumbnails by double-clicking on them so that a red square appears.
    Cheers,
    Elsemiek
    Op 26 dec. 2014, om 00:50 heeft MediaGraphics <[email protected]> het volgende geschreven:
    slideshow image resizing when adding new images
    created by MediaGraphics <https://forums.adobe.com/people/MediaGraphics> in Adobe Muse Bugs - View the full discussion <https://forums.adobe.com/message/7043933#7043933>
    Hi there Elsemiekagain,
    I had to fiddle around with my slide show to get it to work. That is, it worked at first, then went funky, and I had to fiddle. So much fiddling that I can't possibly know what actually made it start to work again.
    And to some degree, this is the way that I find Muse to be in general. That it requires finessing to get it to work as expected. This adds a good deal of time to every development project, though I am getting better at this with practice and experience.
    Most of it is not even things that could be easily put in words as instructions, as many are nanced. But in fairness, this version of Muse is a complete code re-write this year. So we do need to cut Adobe some slack, and give the team time to iron things out.
    If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7043933#7043933 and clicking ‘Correct’ below the answer
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7043933#7043933
    To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"
    Start a new discussion in Adobe Muse Bugs by email <mailto:[email protected]ftware.com> or at Adobe Community <https://forums.adobe.com/choose-container.jspa?contentType=1&containerType=14&container=47 59>
    For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624 <https://forums.adobe.com/thread/1516624>.

  • Way to stop window from resizing when zooming?

    Hi there.
    Is there a way to stop the window from resiging when zooming in/out of my Photoshop documents?
    What seems to happen to me, like, hundreds of times a day is the window keeps resizing when I zoom in and out and much of it goes behind all my palettes. So I drag the resize handle to shrink the window only to have it resize again the next time I zoom in or out.
    I couldn't find a preference for this. When I used to work in Photoshop for WIndows I could have sworn that the window never changed size unless I specifically resized it...
    Thanks!

    Son-of-a-b....
    I swear I looked there a number of times... I swear.
    Thanks.

  • Visibilty of Internal frame in a parent JFrame when it maximize

    i'm working projects on GUI MDI Form.So i've a problem that when we maximize the internal frame
    it should go back to Menu bar of parent frame MDI or title bar of perent frame MDI. Minimisable button and maxim button and closed button should be appear on the back of component where'r the internal going .
    means we can operate the internal frame minimise and close.
    So if anyone who worked on that please help me..............................................

    Without SSCCE, we can't help you!

  • When I maximize my screen on my Mac it hides the menu bar and the typed tool bar at the top of the screen - how do i fix this

    When I maximize the screen on my Mac Book Pro it hides the menu bar and the typed tool bar at the top of the screen as well.  How do I undo this?

    10.7 "Full Screen" is a feature imported from IOS, the land of tiny screens.
    To use a larger window on a REAL computer, adjust the Window's size to suit your needs. Do not use "Full Screen".

  • Weight Watchers Web SiteFood Tracking Page is incomplete when I maximize the window.

    I use Weight Watchers e-tools. I have been accessing it using Firefox since January 2011. Within the last month, when I open the Food Tracker window from the home page, it is minimized. When I maximize the window, I cannot see all of the tracking page. The right side is cut off. I now have to use internet explorer to access this page.

    Reset the page zoom on pages that cause problems, make sure that the window is not maximized:
    *<b>View > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)
    *http://kb.mozillazine.org/Zoom_text_of_web_pages
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • Illustrator Application Window Resizes When Opening Smart Object from PSD

    Hi All, I've taken a vector graphic created in AI CS4 and pasted it into my PSD CS4 doc as a smart object. When the original AI file was created the application window was set as I preferred it, filling my screen. When I double click the Smart Object in PSD to edit it back in Illy, the window that contains the application has been switched off of the fill screen mode and is quite a bit smaller. I know it's small but now I have to click the maximize icon in the application bar to get Illy to fill the screen again. It wouldn't be so bad once, but the application window resizes itself every time I punch back into the smart object from PSD.
    Any ideas on how I can get the AI environment from switching around on its own??
    Win 7, CS4, all patches current, Dual 22" montiors
    thnx,
    jeff

    I just want to point out that when you open the smart object of course it is not the same file as the original but an embedded copy of it.
    That might also have something to do with this issue and might also be a photoshop issue with the smart object and one reason might be that Photoshop is see the image as resolution and Illustrator sees it as a dimension and the teams might be able to do something about this but might not actually be aware of it unless you file a report even if it is not a bug it would then be a feature request.
    They might not be able to do anything about it but then there might be a clever engineer with an idea, so it might be worth the report.

  • JScrollPane resizing problem, I think...

    The Task
    I want to build a dialog that holds different option panels.
    Instead of using a JTabbedPane, I want to use a JTree to select among the different panels.
    I put the tree in a nice scroll pane, place the whole thing in the left side of
    the dialog. I think I have the logic down except for one thing...
    The Problem
    Whenever I click a node when the JTree is expanded, it resizes itself. It does this so that words that go off to the right can be seen.
    I don't want this to happen, but I do have to revalidate the main panel for it to change.
    Apparently, just revalidating the main panel revalidates everything.
    The Question
    Is there a setting in the JTree or the JScrollPane that stops this from happening?
    I have tried to change the LayoutManager, but the same thing happens with GridBagLayout.
    I'll put example code in the following post so you can see my issue. I put the most pertinent code to the front, so that you don't have to read too deeply.
    Can anyone advise me?
    Thanks.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.util.*;
    public class ScrollPaneProblem extends JDialog
       implements TreeSelectionListener
       private JButton jbClose;
       private JTree optionsTree;
       private MainPanel jpMain;
       private ActionListener terminator;
       public ScrollPaneProblem()
          // I would prefer that it stay this size.
          setSize( 535, 375 );
          setResizable( false );
          setTitle( "Preferences" );
          setupGui();
          setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
       protected void setupGui()
          Container contentPane = getContentPane();
             The left side of dialog will hold the option tree.
          optionsTree = buildTheTree();
          JScrollPane scrollPane = new JScrollPane( optionsTree );
          contentPane.add( scrollPane, BorderLayout.WEST );
             The center panel will hold another panel
             that changes according to what has been selected
             in the JTree.
          JPanel centerPanel = new JPanel( new BorderLayout() );
          Box bxButtons = buildTheButtonBox();
          centerPanel.add( bxButtons, BorderLayout.SOUTH );
          jpMain = new MainPanel();
          centerPanel.add( jpMain, BorderLayout.CENTER );
          contentPane.add( centerPanel, BorderLayout.CENTER );
       } // end setupGui()
          Changes the text on the main panel, according to what
          has been clicked in the JTree.
       public void valueChanged( TreeSelectionEvent evt )
          TreePath path = evt.getPath();
          Object obj = path.getLastPathComponent();
          if ( obj instanceof DefaultMutableTreeNode )
             DefaultMutableTreeNode node =
             (DefaultMutableTreeNode)obj;
             obj = node.getUserObject();
             // The problem happens when I do the following...
             jpMain.setText( obj.toString() );
             jpMain.revalidate();
             jpMain.repaint();
          } // end if ( a DefaultMutableTreeNode )
       } // end valueChanged( TreeSelectionEvent )
       private JTree buildTheTree()
          // First, build the parent nodes
          Object [] smurfNodes =
             "Smurfette", "Vanity", "Papa Smurf",
             "Greedy Smurf", "Lazy Smurf",
             "O.J., the ostracized orange smurf"
          ParentNode theSmurfs = new ParentNode(
                                  "The Smurfs", smurfNodes );
          Object [] dwarfNodes =
             "Doc", "Happy", "Dopey", "Sneezy",
             "Scratchy", "Sniffy", "Stuffy Head",
             "Fever", "So you can rest medicine"
          ParentNode theDwarfs = new ParentNode(
                                  "The Seven Plus Dwarfs", dwarfNodes );
          // These are all the nodes that go on the tree.
          Object [] theNodes =
             "Scooby Doo",
             "Inspector Gadget",
             "Mighty Mouse",
             "Captain Caveman",
             theSmurfs,
             theDwarfs
          JTree theTree = new JTree( theNodes );
          theTree.addTreeSelectionListener( this );
          return theTree;
       } // end buildTheTree()
       public Box buildTheButtonBox()
          Box box = Box.createHorizontalBox();
          box.add( Box.createHorizontalGlue() );
          // Make it so that we can close this JDialog.
          jbClose = new JButton( "Exit" );
          jbClose.addActionListener( terminator );
          box.add( jbClose );
          box.add( Box.createHorizontalGlue() );
          // help button that does absolutely nothing.
          JButton jbHelp = new JButton( "Help" );
          box.add( jbHelp );
          box.add( Box.createHorizontalGlue() );
          return box;
       } // end buildTheButtonBox()
       // Main entry point.
       public static void main( String [] args )
          JDialog dialog = new ScrollPaneProblem();
          dialog.setVisible( true );
       // So we can shut the dialog off
       static
          terminator =
          new ActionListener()
             public void actionPerformed( ActionEvent evt )
                System.exit( 0 );
    } // end ScrollPaneProblem class
       This MainPanel class goes in the middle of the dialog.
       My other program switches panels instead of using
       the same panel, but that's too much code to put here.
    class MainPanel extends JPanel
       String theText = "Tell me what to draw";
       Font theFont = new Font( "Sans Serif", Font.PLAIN, 12 );
       Dimension theSize;
       // Draws the selected text
       public void paintComponent( Graphics g )
          super.paintComponent( g );
          theSize = getSize( theSize );
          Font oldFont = g.getFont();
          g.setFont( theFont );
          g.drawString( theText, theSize.width / 10, theSize.height / 2 );
          g.setFont( oldFont );
       public void setText( String text )
          theText = text;
    } // end class MainPanel
       This helps with the JTree parent nodes.
    class ParentNode extends Vector
       String theName;
       public ParentNode( String name )
          this( name, null );
       public ParentNode( String name, Object [] values )
          theName = name;
          if ( values != null )
             addAll( Arrays.asList(values) );
       public String toString()
          return theName;
    } // end ParentNode class

  • JScrollPane Resizing

    Can anyone tell me if there is some method i need to call to have force a JScrollPane to update itself? I have a JComponent inside a JScrollPane and I'm doing some custom graphics within the component. When the graphics are too large i want to scroll.
    From the tutorial, I tried to update the preferred size of the component but that doesn't seem to work. I have to manually resize the window for the scrollbars to resize properly.
    Setting the maximum vertical scroll bar size does work, but my scrollbar policy must always be set to display the scrollbars. In other words, if my scrollbars are already showing, setting the max size works, but if they are not and the graphics resize to large for the first time, the scroll bars are not painted immediately (i need to manually resize).
    Any Suggestions? Thanks in advance.

    needed. Btw, other than the javadocs, do you know of
    a good source for this type of information?This site?
    This is something I had to learn the hard way too; in fact I think a great majority of people learning to build guis in java have this exact same problem. Now that you've seen it and done it you'll know for the future.

  • Make jscrollpane resize automatically while resizing the parent window

    Hello,
    I am using jscrollpane and have different components added to it. When I am resizing parenr frame which contains jscrollpane, then jscrollpane is not getting updated(like gridbaglayout) but manually I can do so using mouse. JScrollPane should resize all components automatically. Any help will really be appreciated.
    regards,
    Ranjan

    Please find the code below. My requirement is that the initial size of below panel should remain static after maximizing the frame.
    import javax.swing.*;
    import java.awt.*;
    public class MainFrame extends JFrame {
    private JSplitPane treesSplitter;
    private JSplitPane splitPaneV;
    private JSplitPane splitPaneH;
    JPanel treesPanel;
    JPanel leftPanel;
    JPanel rightPanel;
    JPanel splashPanel;
    JPanel statusBar;
    JLabel statusMessage;
    MainPanel mainPanel;
    private QueryConsolePanel queryConsolePanel;
    private JTabbedPane tabs = new JTabbedPane();
    GridLayout gridLayout1 = new GridLayout();
    public MainFrame() {
    Container main = getContentPane();
    main.setVisible(true);
    main.show();
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String args[]){
    MainFrame main = new MainFrame();
    main.setLocation(10,10);
    main.setVisible(true);
    main.setSize(1024,805);
    main.show();
    public class MainPanel extends JPanel{
    JTabbedPane tabs;
    JPanel splashPanel;
    MainPanel(JTabbedPane t, JPanel splashP){
    super();
    tabs = t;
    splashPanel = splashP;
    //setLayout(new BorderLayout());
    setLayout(new GridBagLayout());
    public void showSplashPane(){
    remove(tabs);
    // add(splashPanel,BorderLayout.CENTER);
    add(splashPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 1, 0, 1), 608, 350));
    // setBorder(BorderFactory.createEmptyBorder());
    public void showTabs(){
    remove(splashPanel);
    //add(tabs,BorderLayout.CENTER);
    add(tabs, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 1, 0, 1), 608, 350));
    setBorder(BorderFactory.createEmptyBorder());
    private void jbInit() throws Exception {
    this.getContentPane().setLayout(gridLayout1);
    leftPanel = new JPanel();
    leftPanel.setLayout( new BorderLayout() );
    queryConsolePanel = new QueryConsolePanel();
    rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout() );
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    getContentPane().add(leftPanel,BorderLayout.CENTER );
    statusBar = new JPanel();
    statusBar.setLayout(new BorderLayout());
    getContentPane().add(statusBar,BorderLayout.SOUTH);
    statusMessage = new JLabel("Application Ready");
    statusMessage.setFont(new Font("MS Sans Serif",Font.PLAIN, 13));
    statusBar.add(statusMessage,BorderLayout.WEST);
    // create the splash
    splashPanel = new JPanel();
    splashPanel.setLayout( new BorderLayout() );
    mainPanel = new MainPanel(tabs,splashPanel);
    treesPanel = new JPanel();
    treesPanel.setBorder(BorderFactory.createEmptyBorder());
    treesPanel.setLayout(new BorderLayout());
    treesSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    treesPanel.add(treesSplitter, BorderLayout.CENTER);
    treesPanel.setPreferredSize(new Dimension(250,250));
    treesSplitter.setOneTouchExpandable(true);
    treesSplitter.setDividerLocation(400);
    splitPaneV = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    rightPanel.add(splitPaneV,BorderLayout.CENTER);
    splitPaneV.setLeftComponent(treesSplitter);
    mainPanel.setPreferredSize(new Dimension(250,600));
    splitPaneV.setRightComponent(mainPanel);
    mainPanel.showSplashPane();
    splitPaneV.setOneTouchExpandable(true);
    splitPaneV.setDividerLocation(400);
    splitPaneV.setLeftComponent(treesSplitter);
    splitPaneH = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
    //splitPaneH.setDividerLocation(600);
    splitPaneH.setOneTouchExpandable(true);
    splitPaneH.setLeftComponent(rightPanel);
    JTextArea textArea = new JTextArea();
    JPanel textPanel = new JPanel();
    textPanel.setLayout(new BorderLayout());
    textPanel.add(textArea,BorderLayout.SOUTH);
    textPanel.setPreferredSize(new Dimension(608, 20));
    splitPaneH.setRightComponent(textPanel);
    leftPanel.add( splitPaneH, BorderLayout.CENTER );
    }

  • GUI resizes when calling JLabel.setText()

    Case:
    I have a GUI with a GridbagLayout.
    This is the code for building the GUI.
    Important bits:
    please note the scrollConsole and adding it way at the end, because that's getting bigger:
    NOTE: KwartoButtons are a selfmade class that behaves like a button.
         setSize(600,600);
              Container p1 = getContentPane();
              p1.setLayout(new GridBagLayout());
                        GridBagConstraints c = new GridBagConstraints();
                        c.gridx = 0;
                        c.insets.set(5,8,5,8);
                   p1.setBackground(Color.DARK_GRAY);
                          panelVeld = new JPanel(new GridLayout(4,4));
                          panelStukken = new JPanel(new GridLayout(4,4));
                          labelVeld = new JLabel("Speelveld");
                          labelOngespeeld = new JLabel("Ongespeelde Stukken");
                        buttonStop = new JButton("Stop");
                          buttonConsole = new JButton("Hide/Show Console");
                          buttonStart = new JButton("Start");
                   textAreaConsole = new JTextArea("");
                   buttonPanel = new JPanel(new FlowLayout());
                   textAreaConsole.setFont(new Font("Courier",Font.PLAIN, 12));
                   aanZet = new JLabel("Niemand aan zet");
                          labelVeld.setForeground(Color.LIGHT_GRAY);
                          labelOngespeeld.setForeground(Color.LIGHT_GRAY);   
                       aanZet.setForeground(Color.LIGHT_GRAY);
                       scrollConsole = new JScrollPane(textAreaConsole,                   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                      buttonPanel.add(buttonStart);
                      buttonPanel.add(buttonStop);
                      buttonPanel.setBackground(Color.DARK_GRAY);
                     for(int i=0; i < veld.length; i++)
                          veld[i] = new KwartoButton(null, i, true);
                          veld.addMouseListener(this);
                   veld[i].setEnabled(false);
                   panelVeld.add(veld[i]);
              Set<Stuk> stukkenSet = spel.getOngespeeld();
              int i=0;
              for(Stuk stuk: stukkenSet)
                   stukken[i] = new KwartoButton(stuk, i, false);
                   stukken[i].addMouseListener(this);
                   stukken[i].setEnabled(false);
                   panelStukken.add(stukken[i]);
                   i++;
              c.fill = GridBagConstraints.NONE;     
              c.gridx = 0;
                   p1.add(labelVeld, c);
              c.gridx = 1;
                   p1.add(labelOngespeeld, c);
              c.weightx = 0.5;
              c.weighty = 0.9;
              c.fill = GridBagConstraints.BOTH;     
              c.gridx = 0;
                   p1.add(panelVeld, c);
              c.gridx = 1;
                   p1.add(panelStukken, c);
              c.fill = GridBagConstraints.VERTICAL;
              c.gridx=0;
              c.gridwidth=2;
              c.weightx=0;
              c.weighty=0;
              p1.add(aanZet,c);
              c.fill = GridBagConstraints.VERTICAL;     
              c.weighty = 0.0;               
              c.gridy=3;
              c.gridwidth=1;
              c.gridx=0;
                   p1.add(buttonPanel, c);
              c.gridx=1;
                   p1.add(buttonConsole, c);
              c.gridwidth = GridBagConstraints.REMAINDER;     
              c.gridx=0;
              c.gridy=4;
              c.weightx = 1.0;
    c.weighty = 0.1;     
                   c.fill = GridBagConstraints.BOTH;
              p1.add(scrollConsole, c);          
    This is the code I run when the resize happens:
    public void setMessage(String s)  {
    String message =""
    message =s
                  if(!message.equals("")) {
                       addToConsole(message);
                       aanZet.setText(message);
    public void addToConsole(String s)  {
                   // Determine whether the scrollbar is currently at the very bottom position.
                   JScrollBar vbar = scrollConsole.getVerticalScrollBar();
                   boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());
                   // append to the JTextArea (that's wrapped in a JScrollPane named 'scrollPane'
                   textAreaConsole.append(s+"\n");
                   // now scroll if we were already at the bottom.
                   if( autoScroll ) textAreaConsole.setCaretPosition( textAreaConsole.getDocument().getLength() );
         }What my GUI does: When I invoke setMessage(), my scrollConsole grows about one line, until it overpowers the entire GUI (except the buttons).
    If I remove the 'auto-scrolldown' functionality of addToConsole, it still resizes, so I reckon that's not the problem.

    Here you go.
    Thanks in advance.
    import java.awt.*;
    import javax.swing.*;
    * SSCCE Class for my problem.
    * Problem: GUI Resizes after calling the update method.
    public class TestingClass extends JFrame {
                   private JTextArea textAreaConsole;
                   private JLabel aanZet;
                   private JScrollPane scrollConsole;
         public void update(String s) {          //the problematic method
                       addToConsole(s);                         
                       aanZet.setText(s);
       public void addToConsole(String s) { //adds text to console
                   // Determine whether the scrollbar is currently at the very bottom position.
                   JScrollBar vbar = scrollConsole.getVerticalScrollBar();
                   boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());
                   // append to the JTextArea (that's wrapped in a JScrollPane named 'scrollPane'
                   textAreaConsole.append(s+"\n");
                   // now scroll if we were already at the bottom.
                   if( autoScroll ) textAreaConsole.setCaretPosition( textAreaConsole.getDocument().getLength() );
         public TestingClass() {
              super("Test");
              buildGUI();
              setVisible(true);
              update("a");
              update("b");
              update("c");
                   update("d");
                        update("e");
                             update("f");
                                  update("g");
                                       update("h");
                                            update("i");
                                                 update("j");
                                                      update("k");
                                                           update("l");
                                                                update("m");
                                                                     update("n");
                                                                          update("o"); //add more to see more effect, remove to kill problem
         public void buildGUI() { //building the gui
              setSize(600,600);
              Container p1 = getContentPane();
              p1.setLayout(new GridBagLayout());
                        GridBagConstraints c = new GridBagConstraints();
                        c.gridx = 0;
                        c.insets.set(5,8,5,8);
                        JPanel panelVeld = new JPanel(new GridLayout(4,4));
                JPanel panelStukken = new JPanel(new GridLayout(4,4));
                        textAreaConsole = new JTextArea("");
                        textAreaConsole.setFont(new Font("Courier",Font.PLAIN, 12));
                        aanZet = new JLabel("Test!");
                      scrollConsole = new JScrollPane(textAreaConsole, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                 for(int i=0; i < 16; i++)
                          panelVeld.add(new JButton("x"));
                          panelStukken.add(new JButton("y"));
          c.weightx = 0.5;
          c.weighty = 0.9;
          c.fill = GridBagConstraints.BOTH;     
          c.gridx = 0;
                p1.add(panelVeld, c);
          c.gridx = 1;
                   p1.add(panelStukken, c);
                 c.fill = GridBagConstraints.VERTICAL;
                 c.gridx=0;
                 c.gridwidth=2;
                 c.weightx=0;
                 c.weighty=0;
                      p1.add(aanZet,c);
                 c.gridwidth = GridBagConstraints.REMAINDER;     
                 c.gridx=0;
                 c.gridy=4;
                 c.weightx = 1.0;
          c.weighty = 0.1;                    
                   c.fill = GridBagConstraints.BOTH;            
                      p1.add(scrollConsole, c);
    public static void main(String[] args) { //starting up!
              new TestingClass();
    }

  • JScrollPane resize policy

    Hi.
    When you resize a jframe with JScrollPane inside, the top left corner maintains fixed position, that is the point visible in the corner does not change.
    I would like to keep the center point fixed, that is that a point which is visible exactly in the center should be also in the center after resize.
    How to achieve this with JScrollPane? Efficiently, without double repainting after resize.
    Thanks for any help.

    One way is by leveraging JViewport#setViewPosition. Example with some graphics so the effect can be seen:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FreezeCenterScrollPane {
       private JPanel panel;
       private JScrollPane scrollPane;
       private int midX = 0;
       private int midY = 0;
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new FreezeCenterScrollPane().makeUI();
       public void makeUI() {
          panel = new JPanel() {
             @Override
             public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.setColor(Color.RED);
                int w = getWidth();
                int h = getHeight();
                for (int i = 0, j = 0; i < w / 2 && j < h / 2; i += 20, j += 20) {
                   g.drawRect(i, j, w - 2 * i - 1, h - 2 * j - 1);
          panel.setPreferredSize(new Dimension(1000, 1000));
          scrollPane = new JScrollPane(panel);
          scrollPane.addComponentListener(new ComponentAdapter() {
             @Override
             public void componentResized(ComponentEvent e) {
                Point oldPosition = scrollPane.getViewport().getViewPosition();
                Rectangle rect = scrollPane.getViewportBorderBounds();
                if (midX != 0 || midY != 0) {
                   int diffX = midX - rect.width / 2;
                   int diffY = midY - rect.height / 2;
                   Point newPosition = new Point(Math.max(0, oldPosition.x + diffX),
                         Math.max(0, oldPosition.y + diffY));
                   scrollPane.getViewport().setViewPosition(newPosition);
                midX = rect.width / 2;
                midY = rect.height / 2;
          JButton increase = new JButton("Increase panel size");
          increase.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
                resizePanel(50);
          JButton decrease = new JButton("Decrease panel size");
          decrease.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
                resizePanel(-50);
          JFrame frame = new JFrame();
          frame.setGlassPane(new JComponent() {
             @Override
             public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.setColor(Color.BLUE);
                int w = getWidth();
                int h = getHeight();
                g.drawLine(w / 2, 0, w / 2, h);
                g.drawLine(0, h / 2, w, h / 2);
          frame.getGlassPane().setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 400);
          frame.add(increase, BorderLayout.NORTH);
          frame.add(scrollPane, BorderLayout.CENTER);
          frame.add(decrease, BorderLayout.SOUTH);
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       private void resizePanel(int increment) {
          Dimension d = panel.getPreferredSize();
          panel.setPreferredSize(new Dimension(d.width + increment,
                d.height + increment));
          panel.revalidate();
    }Scroll to the approximate center of the JPanel (the smallest rectangle) and resize the JFrame.
    db

Maybe you are looking for

  • How to access Trace file in storage account

    Hi, I am new to Azure Cloud, I would like to know how to access the trace file stored in Storage account. We have implemented diagnostics & traces, I have no idea how to access the trace file. I have no idea what are the folders created inside the st

  • What are BC4J properties used for? ( Properties )

    Hi, I've been looking into <properties> tag in BC4J. I'm looking after runtime validation of attributes. A definition I found was the following: Properties are name/value pairs of type string that you can use as metadata to drive runtime behavior. Is

  • Domain bindings doesn't show short text of domains

    Hello forum, I am facing a problem in a bsp view. I want to create a dropdownListBox where the values displayed are the short text values in the domain. I found a SDN guide (https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/72d7ac11

  • I can't get ios 4.3.3 to load on my ipod touch gen4 8g

    When prompted i click to update to 4.3.3 and it goes throught the whole download process, and during the "finishing" or "completing" something like that, it stops the update and says the software is corrupted. I have checked to make sure i am using t

  • Where do I find NI-CAN error messages and how do I interpret them?

    I have the following error when using ncWait.vi:  BFF62125.  I am using NI-CAN 2.1.1.  Can you tell me what this error means, in detail?  Also ? I cannot find the error and status information in the NI-CAN 2.1.1 NI-CAN Hardware and Software manual.