Resize of Frame after frame is created

Hi,
I have a tabbed pane inside a Frame. When I press one of the tabs I want to resize the Frame.
Since the tabbed pane is inside the frame I use the following code:
this.getParent().setSize(640,480); // This does not resize the frame
this.getParent().resize(640,480); // This does not resize the frame
I am using Swing.
What could be wrong or how do I resize the frame after the frame has been created?
Thanks.

Hi,
I guees I might have not told every detail.
I have a class called TabbedPane that extends JPanel.
This class then contains a JTabbedPane.
I then have a JMainFrame that extends Frame that in turn creates a TabbedPane.
Inside my TabbedPane class I listen to which Tab the user has selected, depending on which Tab I have to resize the Frame. Here is where I can't get it to work.
if(index == 1) {
Dimension d = new Dimension(640,480);
setPreferredSize(d);
updateUI(); // DOES not work.                              
} else {
Dimension d = new Dimension(400,400);
setPreferredSize(d);
updateUI();
Please help :)
Thanks

Similar Messages

  • Problem with dragged component after resizing the frame

    My application is simple: I am displaying an image on a panel inside a frame (JFrame). I am able to drag the image inside the panel. My problem is that, after dragging the image around, if I am resizing the frame, the image goes back to its original position.
    Does anyone know a workaround?
    I have been using the sample provided by noah in his answer (reply no. 3) to a previous question on this forum: http://forum.java.sun.com/thread.jsp?forum=57&thread=126148
    Thank you!

    Chek out the visibility of your components. Some operations may render them invisible. Use the setVisible( boolean ) to make them visible.

  • Panel doesn't display properly until I resize the frame

    Hiya folks,
    I'm currently trying to write a simple piece of music notation software. This is my first time using swing beyond a relatively simple JApplet and some dialog stuff. Anywho, I ran into a pretty discouraging issue early on. So far I've got a frame with a menu bar and a toolbar on the bottom border. The toolbar contains a button which should draw a new staff panel containing 11 panels (potentially more) within it, alternating between lines and spaces. Sort of like this:
    import javax.swing.*;
    import java.awt.*;
    public class Staff extends JPanel {
       private static JPanel nsp1,nsp3,nsp5,nsp7,nsp9,nsp11;
       private static JPanel nsp2,nsp4,nsp6,nsp8,nsp10;
       private ImageIcon image= new ImageIcon(this.getClass().getResource( "icons/treble clef.gif"));
        public Staff(){
        setLayout(new GridLayout(11,1));
        add(nsp1= new NoteSpace());
        add(nsp2= new LineSpace());
        add(nsp3= new NoteSpace());
        add(nsp4= new LineSpace());
        add(nsp5= new NoteSpace());
        add(nsp6= new LineSpace());
        add(nsp7= new NoteSpace());
        add(nsp8= new LineSpace());
        add(nsp9= new NoteSpace());
        add(nsp10= new LineSpace());
        add(nsp11= new NoteSpace());
    static class NoteSpace extends JPanel{
        public NoteSpace(){
        setPreferredSize(new Dimension(this.getWidth(),2));
    static class LineSpace extends JPanel{
          public LineSpace(){
          setPreferredSize(new Dimension(this.getWidth(),1));
          public void paint(Graphics g) {
              super.paint(g);
              g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
    }Anyway, this panel displays as a tiny box wherein nothing is visible until I resize the frame. Really frustrating. And I have have no idea what the problem might be. Here's the actionlistener:
    jbtcleff.addActionListener(new ActionListener (){
            public void actionPerformed (ActionEvent e){
                staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
                panel.add(staff);
                staff.repaint();
            });...which is located in a custom jtoolbar class within the Main class, an extension of JFrame:
    public class Main extends JFrame{
       JMenuBar jmb=new CustomMenuBar();
       JToolBar jtb= new CustomToolBars("ToolBar");
       static boolean isStaff=false;
       static boolean isNote=false;
       static JPanel panel = new JPanel();
       private static Staff staff= new Staff();
        private static Toolkit toolkit= Toolkit.getDefaultToolkit();
       private static Image image=toolkit.getImage("C:/Users/tim/Documents/NetBeansProjects/ISP/src/MusicGUI/icons/treble clef.jpg");
        private static Cursor noteCursor = toolkit.createCustomCursor(image,new Point(0,0),"Image"); 
       public Main (String m) {   
            super(m);
            setJMenuBar(jmb);    
            getContentPane().add(jtb,BorderLayout.SOUTH);       
            panel.setLayout(new CardLayout(60,60));
            getContentPane().add(panel);
    public static void main (String[]args){
            JFrame frame= new Main("Music");
            frame.setSize(800,400);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.setIconImage(image);
           Sorry for all the code. I'm desperate.
    Thanks!

    Oh my... have you been through the Swing tutorial?
    Let's look at some of your code,
    static class NoteSpace extends JPanel{
        public NoteSpace(){
        setPreferredSize(new Dimension(this.getWidth(),2));
    static class LineSpace extends JPanel{
          public LineSpace(){
          setPreferredSize(new Dimension(this.getWidth(),1));
          public void paint(Graphics g) {
              super.paint(g);
              g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
    }Here, NoteSpace and LineSpace are being set to a preferred size of 0x2 pixels, and 0x1 pixels respectfully. If you want them at 0 width, how do you expect them to show? In particular, NoteSpace isn't doing anything special. It's just a panel. Why an inner class? Lastly you should not override paint() for SWING. That's AWT stuff. For Swing, you override paintComponent(Graphics g) .
    Then we have this
    jbtcleff.addActionListener(new ActionListener (){
            public void actionPerformed (ActionEvent e){
                staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
                panel.add(staff);
                staff.repaint();
            });I'm not sure what the variable jbtcleff is, but it seems you are adding your Staff panel to "panel" every time a button is pressed.... why? Why not just add it once (outside the action listener) and be done with it. Your panel object has a CardLayout, so I assume you meant to create a new+ staff panel everytime a button is pressed, and then add it to the card layout panel. Even so, setBounds(...) does not seem pertinant to this goal. (In fact, in most situtations the use of setBounds(...) is the antithesis of using layout managers).
    The problem you mentioned though seems to be related to the use of a JPanel (your Staff class) that adds zero-width compontents to a grid array.

  • Help setPreferredSize and resizing a frame

    Hey,
    I have an internal JFrame that contains a JPanel which contains an image. The JPanel is the only compnent of the internal JFrame and must take up the whole of the space in the frame. The image must take up the whole of the Jpanel.
    At the moment the image is drawn in the paint component part of the JPanel:
         // draw the racing track
         g.drawImage(track, 0, 0, imageWidth, imageHeight, this);
    I set the preferred size of the JPanel so that the JFrame fits exactly around the image. This is to avoid clipping that would occur if i set the frame to the size of the image. This is implemented in the constructor of the JPanel :
    // track is the image i am trying to draw
         imageWidth = track.getWidth(this);
         imageHeight = track.getHeight(this);
         setPreferredSize(new Dimension(imageWidth, imageHeight));
    In the JInternalFrame I extend I call the pack() method; I believe this is what sets the frame to the right size so that no clipping occurs.
    This works fine; the image currently appears with no clipping. However now I want to resize the internal frame. When this happens I want the image to be resized so that it can appear larger or smaller but it must maintain its original proportions.
    I have the following event listener in place in the class that creates all of the internal frames :
    tFrame.addComponentListener(new ComponentAdapter() {
    public void componentResized(ComponentEvent evt) {
    tFrameComponentResized(evt);
    private void tFrameComponentResized(ComponentEvent evt) {
         trackWidth = tFrame.getWidth();
         trackHeight = tFrame.getHeight();
    I am not sure how to continue from here. Any help would be greatly appreciated!!
    Thanks Guys (and gals!)
    Alex.

    I have no idea if this is what you were looking for :import javax.swing.*;
    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.net.URL;
    import java.net.MalformedURLException;
    public class ResizableImage extends JPanel {
         private Image theImage;
         public ResizableImage(Image anImage) {
              if (anImage.getWidth(null) == 0) throw new IllegalArgumentException("Image's width is null");
              if (anImage.getHeight(null) == 0) throw new IllegalArgumentException("Image's height is nul");
              theImage = anImage;
         public Dimension getPreferredSize() {
              return new Dimension(theImage.getWidth(null), theImage.getHeight(null));
         protected void paintComponent(Graphics g) {
              super.paintComponents(g);
              Graphics2D g2D = (Graphics2D)g;
              Dimension available = getSize();
              if (available.width * available.height == 0) return;
              Dimension image = new Dimension(theImage.getWidth(null), theImage.getHeight(null));
              if (image.width * image.height == 0) return;
              if (image.equals(available)) {
                   g2D.drawImage(theImage, 0, 0, null);
                   return;
              double scale;
              if (available.height * image.width < available.width * image.height) {
                   scale = (double)available.height / (double)image.height;
              } else {
                   scale = (double)available.width / (double)image.width;
              g2D.drawImage(theImage, AffineTransform.getScaleInstance(scale, scale), null);
         public static void main(String[] args) {
              try {
                   final JFrame frame = new JFrame("Resizable image");
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   URL imageUrl = new URL("http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/images/Bird.gif");
                   frame.setContentPane(new ResizableImage(new ImageIcon(imageUrl).getImage()));
                   SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                             frame.pack();
                             frame.show();
              } catch (MalformedURLException e) {
                   e.printStackTrace();
    }

  • How can we get the reference of XML element on frame as soon as frame is created in Document?

    Hi,
    When ever we copy any text/table cells from any frame, and paste it directly on page, A new Frame is created and the pasted text is placed inside that frame.
    Now to capture this frame creation, We have two possible solutions:
    1) Attach Observer on Document 'kDocBoss' on IID_IHIERARCHY_DOCUMENT and it will notify on frame creation in update function.
    2) Notification event on new story creation.
    Now, I need to perform some changes in the newly created table, for example:
    a)  Need to delete XML tags from newly created frame
    b)  Need to perform action on table cells if any in the created frame.
    But the problem is, when the event comes, I can access basic properties of frame like it's name, type etc, but it does not give me the
    XML element on frame or tables in frame until the event is com pleat.
    I know it's quite a specif requirement, but I guess many of you might have faced these kind of challenges, while processing the event.
    Does any one has any idea how I can get the reference of XML element on frame as soon as it is created?

    Hi Kapoor,
    please give also others a chance, and excuse that I get up late on vacation ;-)
    Anyway, I'd keep the story creation responder to recognize the copy, then combine it with an observer on the backing xml story to catch the associated XML element which is created there. Something like below:
    UIDRef xmlStoryRef = Utils<IXMLUtils>()->GetBackingStore(doc);
    InterfacePtr<ISubject> subject ( xmlStoryRef,IID_ISUBJECT );
    subject->AttachObserver(observer,IID_IIDXMLELEMENT,observer->GetAttachIID());

  • So simple, yet so annoying: problem resizing anchored frame with grab bars

    Asked a question yesterday on how to 'snug' an anchored frame to an image. Got the answer and it works great (Esc-m-p)
    Now... the reason I needed to do this is that when I try to resize a frame with the grab bars, it 'jerks' as I move vertically or horizontally.
    What that means is...
    With borders on, the frame border is a dotted line.
    If I grab the left side of a frame and move my mouse to the right to make the frame smaller, the border doesn't move smoothly -- it jumps a distance of about 1.5 of those dotted lines. Thus I can't always make the frame fit nicely.
    Talked to another Frame user and she said that her's drags smoothly.
    So... am I missing a setting somewhere? Any thoughts would be greatly appreciated.

    ##&*!
    I was working over a VPN when I first experienced the problem... everything was slower than molasses. Set Snap off, did some other work, Frame crashed.
    Setting didn't persist, but everything had taken so long I forgot to check it.
    Gah. Yes, Snap off works wonders when it's *actually* off.

  • Resizing graphics frames that have stroke/keylines

    When I resize a graphic frame (with a placed image in it) that has a stroke/keyline, the stroke changes weight and I have to reapply the Object Style which sets the weight. How can I keep the same weight when I resize?
    Also is there a way of changing the default behaviour of SHIFT+Resize box with mouse so that it resizes the frame AND content rather than having to use the more cumbersome ALT+SHIFT+mouse resize? I do that far more often then just resizing the frame and keeping the ratio!

    Scaling Stroke Issue: On the menu bar at the far right, select the flyout and you will see the option "Adjust Stroke Weight When Scaling" here you can deselect to turn off
    Resizing Issue: For just one image, select image, Object > Fitting > Frame Fitting Options > Turn on Autofit and Desired Fitting Option
    Resizing Issue: For multiple images, Object Styles > select stye(s) > Frame Fitting Options > Turn on Autofit and Desired Fitting Option

  • How to resize a frame to the dimensions of the inner image?

    Hi,
    I'm preparing a JS script.
    I need to resize a frame (InDesign) to the dimensions of an inner image (in fact, the image contained by the frame itself).
    So:
    1) I need to control if the frame is bigger (larger) than the image inside it.
    2) If (1) it's true, I need to obtain the dimensions of the inner image and apply them to the frame.
    3) At the end, I will have that the frame matches perfectly the image.
    Is it possible?
    Thanks and best regards,
    Francesco Jonus

    1) I need to control if the frame is bigger (larger) than the image inside it.
    How do you define this?
    It's obvious for the one on the left, but what about the one on the right?
    If you just care about area, then compute the area and check:
    fb = app.selection[0].geometricBounds;
    framewidth = fb[3]-fb[1];
    frameheight = fb[2]-fb[0];
    framesize = framewidth * frameheight;
    ib = app.selection[0].images[0].geometricBounds;
    imagewidth = ib[3]-ib[1];
    imageheght = ib[2]-ib[0];
    imagesize = imagewidth * imageheight;
    if (framesize < imagesize) {
       alert("Frame is smaller!");

  • Adobe consistently crashes when resizing a frame

    I'm helping a company which publish a review every month with InDesign. The entire document is divided into three columns. Only some titles cover the 3 columns. That seems to be these titles which makes Indesign crashing. As soon as I resize a frame just above this kind of title Indesign crash instantly. I thought about paragraph style, links, layers, but all my tests has been uneffective, impossible to find the reason why Indesign crash. Does someone have an idea to help dealing with it ?
    I'm sorry for this incorrect English and hope some will understand my issue.
    Blaise

    The crash report doesn't show me spscifically what's wrong becasue I'm not an expert at reading them, but it does show it's text related.
    To check to see if span/split is used, you would select the paragraph that spanns the columns and check the settings. Yes, it's a pain to go back to the old way, but if youare crashing because of spanned columns it doesn't make a lot of sense to continue with them.
    Other users have reported problems with the span/split feature.

  • Resize a Frame height only

    Hello
    I know that I can resize a frame by setting this frame to resizable. Now I want to resize only height, not width. How I can do that
    Many thanks
    shuho

    hey,
    you could add a component listener to your frame...
    frame.addComponentListener(new ComponentAdapter() {
      public void componentResized(ComponentEvent event) {
        frame.setSize(200, frame.getHeight())); // width is always 200
    });hope that helps :)

  • Can I resize video frame?

    I have the Canon Vixia HF R400, which is lovely. But the video frame is very wide and thin. Is there a way to resize the frame so that it's more square-ish, and less long, thin cinematic rectangle?

    Hi Heatherelena,
    The shape of the recorded video is a by-product of the aspect ratio (the size of the width and the size of the height) of the movie.  This ratio cannot be changed from 16:9.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Stop From Resizing a Frame

    Which method to use, to stop some one from resizing a frame??
    No maximizing or resizing of the frane.

    setResizable(boolean resizable)
    http://java.sun.com/j2se/1.3/docs/api/

  • Frame being created when linking a Word file

    Robohelp HTML version 8.0.2.208
    I have recently been given a new PC on which RoboHelp 8 has been reinstalled and my version of Microsoft Office updated from Office 2003 to Office 2007. Previous to this upgrade I was using the Link > Word Document feature without any problem for both Word and RTF files. However, following the upgrade when I now link a Word document or RTF file I get the following two issues:
    1) Each topic is now created within a frame using the <div class="WordSection1"> token. No frame was created previously.
    2) The first topic of the linked file is now repeated with the first instance having a htm file name that includes the Heading name plus the first line of text from the file (even though the first line of text is set to a different style). The resulting topic has no content, simply an empty frame.
    My operating system has not changed and remains as Microsoft Windows XP - Service Pack 3.
    Does anyone know if there is a setting in RoboHelp somewhere that I have not reset with the new install, or could this be a Micorsoft Office issue?
    Thanks,
    Chris

    I'm seeing the same, albeit with Word 2010. Right now I cannot see any way around it. Note that to remove it, it is only necessary to remove the opening DIV tag. RoboHelp removes the closing tag for you.
    Not ideal but I cannot see any way of avoiding it.
    Please follow this link and report it as a bug.
    http://www.Adobe.com/cfusion/mmform/index.cfm?name=wishform&product=38
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • After Effects error: creating movie - bad parameter (-50) (44::36)

    Hello,
    When I am trying to render a composition to Mov. file with the following preferances:
    FULL HD 1920X1080 (interlaced)
    Lossless (Animation)
    I get this error message:
    "After Effects error: creating movie - bad parameter (-50) (44::36)"
    Would anyone happen to know know what might be th problem?
    Thank you
    Giannis

    Thank you very much! I think I found the solution. I wasn't
    putting any keyframes. With Animation codec, you
    have to set keyframes every fev frames..

  • I have iPhoto 11 installed on my iMac. Has been working for last several months ok. I am trying to create photo books but it gets hung up after I select create book. Does not create the project.  Used to work but won't create any projects

    ILife 11 (iphoto 11) installed over a year ago with no issues. Have been creating Apple Books with no issues till now.  iPhoto now will not create books, calenders or anything else. After I select "create" it does nothing. Used to work Ok. Program seems to stall and do nothing. I can still look at events and other picture files but it will now not create a "project" / "book"  Anyone with a similar issue????

    ILife 11 (iphoto 11) installed over a year ago with no issues. Have been creating Apple Books with no issues till now.  iPhoto now will not create books, calenders or anything else. After I select "create" it does nothing. Used to work Ok. Program seems to stall and do nothing. I can still look at events and other picture files but it will now not create a "project" / "book"  Anyone with a similar issue????

Maybe you are looking for