Title and JFrame size

hello,
My problem is the next one :
-when I use the pack() method on my JFrame it doesn't use the title bar size...so the title is often cut.
-when I use the frame.setSize() method, the size of the frame is dependant of the system and the computer...
How can i solve my problem ?
thanks,
fleur.

Hi Zharapic,
Set the preferred size of the JFrames width based on the length of the title string.
Something like this.
//the minimum width of the frame without a title.
int MINIMUM_SIZE = 100;
FontMetrics metrics = jframe.getFontMetrics(jframe.getFont());
int titleOffset = metrics.stringWidth(jframe.getTitle());
//you now have the length of the title so you can set the
//preferred size of the JFrame.
jframe.setPreferredSize(jframe.getHeight(), MINIMUM_SIZE+titleOffset);This way the JFrame should always fit the title when you call pack.
hope this helps.
N35Sy

Similar Messages

  • Problem with ScrollPane and JFrame Size

    Hi,
    The code is workin but after change the size of frame it works CORRECTLY.Please help me why this frame is small an scrollpane doesn't show at the beginning.
    Here is the code:
    import java.awt.*;
    public class canvasExp extends Canvas
         private static final long serialVersionUID = 1L;
         ImageLoader map=new ImageLoader();
        Image img = map.GetImg();
        int h, w;               // the height and width of this canvas
         public void update(Graphics g)
            paint(g);
        public void paint(Graphics g)
                if(img != null)
                     h = getSize().height;
                     System.out.println("h:"+h);
                      w = getSize().width;
                      System.out.println("w:"+w);
                      g.drawRect(0,0, w-1, h-1);     // Draw border
                  //  System.out.println("Size= "+this.getSize());
                     g.drawImage(img, 0,0,this.getWidth(),this.getHeight(), this);
                    int width = img.getWidth(this);
                    //System.out.println("W: "+width);
                    int height = img.getHeight(this);
                    //System.out.println("H: "+height);
                    if(width != -1 && width != getWidth())
                        setSize(width, getHeight());
                    if(height != -1 && height != getHeight())
                        setSize(getWidth(), height);
    }I create frame here...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JFrame;
    public class frame extends JFrame implements MouseMotionListener,MouseListener
         private static final long serialVersionUID = 1L;
        private ScrollPane scrollPane;
        private int dragStartX;
        private int dragStartY;
        private int lastX;
        private int lastY;
        int cordX;
        int cordY;
        canvasExp canvas;
        public frame()
            super("test");
            canvas = new canvasExp();
            canvas.addMouseListener(this);
            canvas.addMouseMotionListener(this);
            scrollPane = new ScrollPane();
            scrollPane.setEnabled(true);
            scrollPane.add(canvas);
            add(scrollPane);
            setSize(300,300);
            pack();
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void mousePressed(MouseEvent e)
            dragStartX = e.getX();
            dragStartY = e.getY();
            lastX = getX();
            lastY = getY();
        public void mouseReleased(MouseEvent mouseevent)
        public void mouseClicked(MouseEvent e)
            cordX = e.getX();
            cordY = e.getY();
            System.out.println((new StringBuilder()).append(cordX).append(",").append(cordY).toString());
        public void mouseEntered(MouseEvent mouseevent)
        public void mouseExited(MouseEvent mouseevent)
        public void mouseMoved(MouseEvent mouseevent)
        public void mouseDragged(MouseEvent e)
            if(e.getX() != lastX || e.getY() != lastY)
                Point p = scrollPane.getScrollPosition();
                p.translate(dragStartX - e.getX(), dragStartY - e.getY());
                scrollPane.setScrollPosition(p);
    }...and call here
    public class main {
         public main(){}
         public static void main (String args[])
             frame f = new frame();
    }There is something I couldn't see here.By the way ImageLoader is workin I get the image.
    Thank you for your help,please answer me....

    I'm not going to even attempt to resolve the problem posted. There are other problems with your code that should take priority.
    -- class names by convention start with a capital letter.
    -- don't use the name of a common class from the standard API for your custom class, not even with a difference of case. It'll come back to bite you.
    -- don't mix awt and Swing components in the same GUI. Change your class that extends Canvas to extend JPanel instead, and override paintComponent(...) instead of paint(...).
    -- launch your GUI on the EDT by wrapping it in a SwingUtilities.invokeLater or EventQueue.invokeLater.
    -- calling setSize(...) followed by pack() is meaningless. Use one or the other.
    -- That's not the correct way to display a component in a scroll pane.
    Ah, well, and the problem is that when you call pack(), it retrieves the preferredSize of the components in the JFrame, and you haven't set a preferredSize for the scroll pane.
    Please, for your own good, take a break from whatever it is you're working on and go through The Java™ Tutorials: [Creating a GUI with JFC/Swing|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]
    db

  • How to set JFrame MEX and MIN size ?

    Hello All,
    i want to set my jframe meximum and minimum size but
    i cant find any method please help me.
    i m thanksfull.
    Arif.

    In this case minimum size is 100 and max is 400!
    I hope it helps
    import java.awt.*;
    import javax.swing.JFrame;
    import java.awt.event.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Frame1 extends JFrame {
    final int minw=100;
    final int maxw=400;
    final int minh=100;
    final int maxh=400;
    public Frame1() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    Frame1 frame1 = new Frame1();
    frame1.setBounds(0,0,100,100);
    frame1.setVisible(true);
    private void jbInit() throws Exception {
    this.addComponentListener(new java.awt.event.ComponentAdapter() {
    public void componentResized(ComponentEvent e){
    frame_resized();
    public void frame_resized(){
    int hh=this.getHeight();
    int ww=this.getWidth();
    if((!(minh<hh && hh<maxh))||( !(minw<ww && ww <maxw))){
    if( hh<minh)
    hh=minh;
    if( hh>maxh)
    hh=maxh;
    if( ww<minw)
    ww=minh;
    if( ww>maxw)
    ww=maxw;
    this.setSize(ww,hh);
    Bye Alessio

  • Is there any way to turn off the auto formatting in Pages?  I just want to type a letter and add pictures and titles, and Pages keeps changing font sizes and doesn't let me "Do it my way".  I HATE this!

    Is there any way to turn off the auto formatting in Pages?  I'm using a blank document, so I figured I could write my letter and add pictures any way I wanted to.  But NO!  Pages keeps changing the font size!  I typed a large heading as a title, and when I try to change to a smaller font for the body of the letter, it changes the size back to the larger size!  I am getting SO FRUSTRATED!  I've spent over an hour trying to get the stupid program to let me just type my letter!  Can anyone help?

    The only one left is the "unsubmitted text" dialogue, which would not be a problem if I were not a Facebook user; after updating the "Richard is..." field (which does not require a manual submit to actually send) I get the above message. This is obviously Safari just not realising that the info has been sent and is therefore (I imagine) one for Apple themselves to answer!!
    You're welcome Rich. Glad to help.
    Not being a Facebook User, I'm not sure how to respond to the error situation. However, this would be something to report to Apple as a bug via the Safari Menu. First, open to the page in question, then select "Report Bugs to Apple".
    Mahalo for the and Aloha from Big Island.

  • Is it possible to change the CATEGORY TITLE font color and/or size of each tile group in start screen, when the tiles are sorted by CATEGORY?

    TIA.

    Q.  Is it possible to change the CATEGORY TITLE font color and/or size of each tile group in start screen, when the tiles are sorted by CATEGORY?
    A.  No
    Carey Frisch

  • Formerly I could download YouTube videos by double clicking the largest size page element in the Safari activity window address column. Now in V 5.0.5 page elements are not shown, just the page title, and under that about:blank.  Suggestions? Thanks.

    Formerly I could download YouTube videos by double clicking the largest size page element in the Safari activity window address column . Now in V 5.0.5 page elements are not shown, just the page title, and under that "about:blank".  Also, the activity window used to show sequential activity and now each new page replaces the last. Thanks for any suggestions re how to restore previous activity window function.

    Not all YouTube videos are available for downloading, but:
    There is the Free  iTube Grabber which can capture almost any audio and/or video stream (it says here) but only works with Intel Macs.
    http://itube-grabber.en.softonic.com/mac
    Firefox Download Helper is also supposed to work, you have to be logged into YouTube first.
    and the RealPlayer Downloader that comes with RealPlayer SP for Mac from:
    http://www.real.com/realplayer/mac
    which also downloads videos from YouTube.
    There is also iTubeX which allows you to download videos (Flash, HTML5 and others), .mp3 and .swf files from almost every website as easily as possible:
    http://www.macupdate.com/info.php/id/27604/itubex
    Lastly: How to download Flash videos and play them in Quicktime using Perian is explained here:
    http://perian.org/#watch
    It's the video at the bottom of the page.

  • Report generation toolkit: Avoid a separation of title and image at pagebreak in a work document.

    I want to generate a report with the report generation toolkit in LV7.1.
    In that report I use several report VIs to append text, titles and frontpanel images to a word document template (Office 2003). That works fine.
    Depending on the size and text of my generated report, I have sometimes a problem with pagebreaks: A image is set to a new page if there is not enough space to place it on the old one. That’s ok. The text/title above the image is still on the old page. That's right, but I don’t want this. I know in Word you can use the paragraph formatting options to avoid a separation. But with the corresponding VI from the toolkit (word format paragraph (adv)) it seems not to work. With this VI you should have access to "indents and spacing" and to "line and page breaks". I always and only can change the "indents and spacing". En- or Disabling line or page breaks with this VI does not work, nothing changes in a word document.
    Has anyone some suggestions or other solutions?
    Thanks in advance!

    Thanks for your input. You are right, that works and could be an alternative.
    In the meantime I found a solution with creating my own activex vi instead of that from the toolkit as you can see in the attached image. Maybe this could help someone with similar problems...
    Attachments:
    KeepWithNext.JPG ‏46 KB

  • How do I get the book title and author to appear on all pages?

    I'm trying to create a new layout, and I can't quite figure out some of the auto-text boxes.
    I'd like the book title, and author to appear at the top of the pages.
    Also, I'd like the chapter title to be at the top of the page for the subsequent chapter pages, but not in the same size as the chapter title at the beginning of the chapter.
    I've tried copying the chapter text box in layouts, then applying it to the chapter pages.  However, when I reformat the copied box for text size and orientation, the reformat effects all instances of that text box.  Grr.
    (I know this all sounds like too much text and garbage on each page, but it's for an instructional piece that people will likely print a page or two at a time)

    Hello Andy,
    Have you looked at the Layout Section.
    If it is not visible pull down the handle and the master pages are there down the list for you to add and change.
    Just first duplicate any page that you may want to change and then add the name and author titles to that page and press "APPLY"
    I hope this helps…
    Regards,

  • How to export photos with titles in chronological order. Checking box for title and keyword doesn't seem to work

    I want to export a group of JPEG photos including titles in the order in which they were taken.  Checking the box to include titles and key words seems not to work.

    You can not
    exporting creates files - files have no order - the order is set by the program you use to view them - for example in the finder you can view files by the date created, date modified, size, alpha, etc
    So to control the order when viewing in the finder you must have an attribute that the finder can sort on set - the most common way to export photos in a specific order is to make an album in iphoto in the order you want and then export the album using the sequential naming option of the export command - then view them in the finder using a alpha sort - Exporting From iPhoto
    However since you want to retain your existing title that will not work for you

  • Add multiple effects to a title and to a video

    I have an edited video and inserted a title before the video starts. I would like to have the title zoom and while zooming, fade in. I apply the zoom to the begining of the title on my timeline, edit the duration and the start and end size then try to add a fade but the fade overwrites the zoom. On all the videos I found, they drag and drop the effects onto the clips on the timeline (I have to add them to either the front or back) then it appears on the Effect Controls under Video Effects. When I do it, I do not see the effect under that, I can only see the effect options when I click on the effect on the time line.
    I have tried the same thing to the video itself and can only add one effect to each clip.
    What am I doing wrong? How can I add multiple effects to things on my timeline?

    Here is a +1 for Jim's suggestion to look into Keyframing the Fixed Effect>Motion>Scale, to create your Zoom.
    You could well explore Keyframing another Fixed Effect>Opacity, to have more control over your Fade-In too.
    Good luck,
    Hunt

  • Smart forms and Font Sizes

    Hi,
    I'm creating a form and i am trying to place a title with font size around 50, and i tried creating a paragraph type with a font of this size in smart styles, the problem is when i am editing the text node, the font size appears to be right, but when i print it, the font gets much smaller, can anyone help on this?
    Regards,
    Leandro Fonseca

    Thanks, for the quick replies.
    I tried that, i created a paragraph type, and i can see a change in the font size, but its as if there is a limit to the size it displays, i place the font size at 50, but it does not shot that size, maybe a little bigger than normal, but not 50. The font i'm using is HELVE.
    Regards,
    Leandro Fonseca

  • IPhoto "titles" and "comments"

    Hey,
    I am making a slideshow in iDVD with a lot of pictures that im importing from iPhoto. My problem is that the names of the pictures (when I show "titles and comments") are too large and cover important parts of the image. I also noticed that the "comments" was smaller than the "titles". So is there a way for Automater to replace all the "comment" sections with what is in the "title" section for all my pictures in iPhoto? I have never used Automater so any help would be great.
    -church7mouse
    iBook G4   Mac OS X (10.3.9)  

    Create a workflow with a "Run AppleScript" action and replace the (* Your script goes here *) with the following AppleScript. The easiest way to do that is to click on the link, which will open AppleScript Script Editor, and then copy and paste it into the "Run AppleScript" action.
    For this action to work properly you must make sure that before you run the Automator action only the album of interest is selected and not a photo in that album.
    click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "iPhoto"
    set theAlbum to selection
    set thePhotos to every photo of first item of theAlbum
    repeat with aPhoto in thePhotos
    set theOldTitle to title of aPhoto
    set title of aPhoto to comment of aPhoto
    set comment of aPhoto to theOldTitle
    end repeat
    end tell
    </pre>
    PowerBook 12"   Mac OS X (10.4.8)  

  • Dynamic resize of JButton and JFrame in response to Font

    Im supposed to increase the font size of the text with JButton by 1 within each click.
    Eventually the text becomes shorter and less visible like WORD becomes WOR... then WO... etc
    How to make the button always resize with text so that the text is fully visible and JFrame always resize with button so that the button doesn't change its position within the Frame ?
    edit:
    I managed to make buttons resize with increasing font
    by making
    JButton b = new JButton("button");
    b.setHorizontalTextPosition(CENTER);
    b.setVerticalTextPosition(CENTER);However the window size doesnt increase with components ;[
    any help would be appretiated.
    Edited by: pimpcane on Dec 11, 2007 12:16 PM

    Ok I managed to get it working moreless by
    adding pack() to the actionPerformed(...) function
    public void actionPerformed(ActionEvent e)
                 int index = Integer.parseInt(e.getActionCommand());
              int size = buttons[index].getFont().getSize();
              size++;
              buttons[index].setFont(new Font(name, style, size));
              pack();
    }The problem is in the task im given it is forbidden to use pack();
    Is there any other method to obtain the same result of JFrame resizing dynamically in response to components resize ?
    Edited by: pimpcane on Dec 12, 2007 12:13 PM
    Edited by: pimpcane on Dec 12, 2007 12:15 PM

  • Title and Caption

    I have crated a slideshow of still photos and included a title for each image.
    The title appears in a box that goes on top of the image.
    Why does it do this when there is plenty of blank space on either side of the image?
    Is it possible to change where the title of an image appears on the screen?

    Is it possible to change where the title of an image appears on the screen?
    It is in DVDSP. But I'm not sure how to do this in iDVD yet (nor if it's even possible). I'll keep looking though and post back should I find something else.
    Btw ... You can't change the style or size of text for titles and comments in an iDVD slideshow. But you can in DVDSP.
    A less expensive option to DVDSP might be 3rd party apps like:
    http://www.lqgraphics.com/software/phototomovie.php
    or
    http://www.boinx.com/fotomagico/overview/

  • RSS Feed Title and Description

    Can somebody show me how to show the description with this?
    import fl.managers.StyleManager; import fl.events.ListEvent; var logFormat:TextFormat = new TextFormat(); logFormat.font = "Verdana"; logFormat.size = 9; logFormat.bold = true; StyleManager.setStyle("textFormat", logFormat); var rssLoader:URLLoader = new URLLoader (); var rssURL:URLRequest = new URLRequest("http://www.vegasdsports.com/feeds/nba_widget.php"); rssLoader.addEventListener(Event.COMPLETE, rssLoaded); rssLoader.load(rssURL); var rssXML:XML = new XML(); rssXML.ignoreWhitespace = true; function rssLoaded(evt:Event):void { rssXML = XML(rssLoader.data); for(var item:String in rssXML.channel.item) { liLog.addItem( {label:rssXML.channel.item[item].title,link:rssXML.channel.item[item].link} ); } } liLog.addEventListener(ListEvent.ITEM_CLICK,clickedLogF); function clickedLogF(e:ListEvent){ navigateToURL(new URLRequest((liLog.getItemAt(e.index).link))); }
    Thanks in advance

    Hmm, I may be a little late, but its here if anyone else needs it.
    ActionScript 3 Code:
    //startScript
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import fl.managers.StyleManager;
    import flash.text.TextFormat;
    import flash.events.KeyboardEvent;
    var logFormat:TextFormat = new TextFormat();
    logFormat.font = "Arial";
    logFormat.size = 10;
    logFormat.color = 0xFFFFFF;
    logFormat.bold = true;
    StyleManager.setStyle("textFormat", logFormat);
    //RSS Feed
    var rssLoader:URLLoader = new URLLoader();
    var rssURL:URLRequest = new URLRequest("http://yourFileHere.xml");
    rssLoader.addEventListener(Event.COMPLETE, rssLoader1);
    rssLoader.load(rssURL);
    var rssXML:XML = new XML();
    rssXML.ignoreWhitespace = true;
    function rssLoader1(event:Event):void {
    rssXML = XML(rssLoader.data);
    trace(rssXML);
    for(var item:String in rssXML.channel.item) {
      "your list component name here".addItem( {label:rssXML.channel.item[item].title } );
    function selectLog(event:Event):void {
    "your description box here".text = rssXML.channel.item[ event.target.selectedIndex ].description;
    "your list component name here".addEventListener(Event.CHANGE, selectLog);
    //endScript
    Note: You can use a classic text "Dynamic Text" box, size it to how big you want the text to f. From there, get a UI Scrollbar from the components, put it somewhere, and go into its Properties. Go to where it says "Component Paramaters" and then "scrollTargetName". Set this to your textbox/description box name. And there you have it. A full working RSS Feed Title and Description file.
    Let me know if you run into any trouble!

Maybe you are looking for