ContentPane wont be size i want it to be?

Hi i am having trouble with this program i need to make for an exercise, i just need to create the shape of a calender using GridBagLayout. I know that the code i have works because i had it just in a main method before, but now i am trying to make it into an object so i can use it later. the issue is that no matter what the panels that i create are tiny, no matter what values i input for size. i have posted my class and testclass below, let me know if you have any questions
public class TCalander{
    private int calWidth;
    private int calHeight;
    private JPanel pane = new JPanel();
    public TCalander() {
        //blank
    public TCalander(int c_W, int c_H) {
        calWidth = c_W;
        calHeight = c_H;
        pane.setPreferredSize(new Dimension(c_W, c_H));
        createComponents();
    private void createComponents() {
        //create JPanel to be used and make the border black for ease
        JPanel panels[] = new JPanel[50];
        for(int i = 0; i < panels.length; i++) {
            panels[i] = new JPanel();
            panels.setBorder(BorderFactory.createLineBorder(Color.black));
//set the passed through container's layout
pane.setLayout(new GridBagLayout());
//create a set of constraints
GridBagConstraints c = new GridBagConstraints();
//add the top bar
panels[0].setPreferredSize(new Dimension(calWidth, (int)(0.1 * calHeight)));
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 7;
c.gridheight = 1;
c.weighty = (int)(0.1 * 0.05 * calHeight);//5% of top section
pane.add(panels[0], c);
//reset weight
c.weighty = 0;
//add the day labels
for(int i = 0; i < 7; i++) {
panels[i+1].setPreferredSize(new Dimension(100, (int)(0.0358 * calHeight)));
c.gridx = i;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
pane.add(panels[i+1], c);
//add the day boxes
int panelAt = 8;
for(int row = 0; row < 6; row++) {//each row
for(int col = 0; col < 7; col++) {//each column
int sum = (int)(0.1 * calHeight) +
(int)(0.0358 * calHeight) +
(int)(0.1432 * calHeight) +
(int)(0.1432 * calHeight) +
(int)(0.1432 * calHeight) +
(int)(0.1432 * calHeight) +
(int)(0.1432 * calHeight);
panels[panelAt].setPreferredSize(new Dimension(100, (calHeight - sum)));
c.gridx = col;
c.gridy = row + 2;
c.gridwidth = 1;
c.gridheight = 1;
pane.add(panels[panelAt], c);
panelAt++;
public JPanel getPanel() {
return pane;
test class:public static void main(String[] args) {
JFrame frame = new JFrame("GridBagLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(500, 500));
TCalander cal = new TCalander(500, 500);
frame.setContentPane(cal.getPanel());
System.out.println(frame.getContentPane().getPreferredSize());//for debuging
System.out.println(frame.getContentPane().getSize());//for debugging
frame.setVisible(true);
the output is:
java.awt.Dimension[width=500,height=500]
java.awt.Dimension[width=0,height=0]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

I'll reiterate what camickr has said. GridBagLayout is the most difficult one. I don't know why you fill compelled to use it.
import javax.swing.*;
import java.awt.*;
public class TCalander{
    private JPanel pane = new JPanel();
    public TCalander() {
        //blank
    public TCalander(int c_W, int c_H) {
        pane.setPreferredSize(new Dimension(c_W, c_H));
        createComponents();
    private void createComponents() {
        //create JPanel to be used and make the border black for ease
        JPanel panels[] = new JPanel[50];
        for(int i = 0; i < panels.length; i++) {
            panels[i] = new JPanel();
            panels.setBorder(BorderFactory.createLineBorder(Color.black));
//set the passed through container's layout
pane.setLayout(new GridBagLayout());
//create a set of constraints
GridBagConstraints c = new GridBagConstraints();
//add the top bar
c.gridx = 0; c.gridy = 0;
c.gridwidth = 7; c.gridheight = 1;
c.weightx = 1.0; c.weighty = .5;
c.fill = GridBagConstraints.BOTH;
pane.add(panels[0], c);
//add the day labels
for(int i = 0; i < 7; i++) {
c.gridx = i; c.gridy = 1;
c.gridwidth = 1; c.gridheight = 1;
c.weightx = 1.0; c.weighty = .2;
c.fill = GridBagConstraints.BOTH;
pane.add(panels[i+1], c);
//add the day boxes
int panelAt = 8;
for(int row = 0; row < 6; row++) {//each row
for(int col = 0; col < 7; col++) {//each column
c.gridx = col; c.gridy = row + 2;
c.gridwidth = 1; c.gridheight = 1;
c.weightx = 1.0; c.weighty = 1.0;
c.fill = GridBagConstraints.BOTH;
pane.add(panels[panelAt], c);
panelAt++;
public JPanel getPanel() {
return pane;
public static void main(String[] args) {
JFrame frame = new JFrame("GridBagLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TCalander cal = new TCalander(500, 500);
frame.setContentPane(cal.getPanel());
frame.setSize(500,500);
frame.setVisible(true);

Similar Messages

  • Drawling a rectangle creates a Giant rectangle instead of the size I want

    Whenever I try to draw a rectangle/square using the Rectangle Tool, I end up creating a GIANT rectangle instead of size I want (something closer to 400x80 px).
    Here's what I am doing:
    create new layer from Layers Panel
    select Rectangle Tool
    click and hold click to start drawling the rectangle > immediately the coordinate are something like x: -8800 y: -1550 (see pic1)
    if I release the click now, I end up drawling a GIANT rectangle (see pic2)
    now I have to zoom way really far inorder to see the edges of rectangle and be able to resize
    This only happens when I use the Rectangle Tool, not the Rounded Rectangle, Elipse, Polygon, Line or Custom Shapes Tools.
    Any ideas on what I'm doing wrong here? I really appreciate your help!
    I'm using the latest version of Photoshop on a brand new iMac.

    Hi,
    Perhaps under Geometry Options you have fixed size or one of the other options besides unconstrained ticked with a preset size entered?
    You probably want it set to Unconstrained.

  • After update the latest photoshop cc 2014,contact sheet font can't set what point size I want

    After update the latest photoshop cc 2014,contact sheet font can't set what point size I want.

    Yes I do,but I don't understand that :
    Wed Oct 22 2014 16:55:21 GMT+0800 -
    CSXBridge.runFromBridge()
    Wed Oct 22 2014 16:55:21 GMT+0800 - Sending to PS: [
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-1_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-2_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-3_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-4_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-5_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-6_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-7_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-8_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-9_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-10_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-11_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-12_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-13_CC.tif,
      /My_Job/LP_10-14/Michael%20Sloyer/Sloyer%2020x30-14_CC.tif]

  • When trying to use photo as wallpaper, cannot scale the image to size I want.  This feature worked fine with ios6

    When trying to use a photo for wallpaper, cannot scale the image to size I want to use.  Feature worked fine in iOS6

    James, thank you. I'm experiencing the same issue and submitted feelback at that link. I'm trying to use the same pumpkin image I used last year for Halloween on my lock screen and attempting to follow instructions (Move and Scale) and would like to make the image smaller so that it appears BELOW the time and date, but although I'm able to move the image, I'm unable to scale it - make it smaller. I've since tried this with several other photos with the same outcome. It seems that in iOS 7 one can make images bigger, but not smaller. I'm not sure what the logic behind that could be.

  • Getting the print sizes i want

    I am having an issue with photos that I want to size print. If i have a photo all ready to be printed and want to print it as an 8X10, when i put up the crop marks for 8X10, the aera that i want in the photo gets cut off. It is like putting an 8X10 box on the photo versus putting the photo in an 8X10 box. Is there a way to set the file up to print that photo to any size and get that photo to fit the crop size (4X6, 8X10, etc)?
    Thanks, Brian

    I am sending them out to Mpix. When I upload the file and then go select a photo print size, i am not getting what i want. I just don't want to have photos up there and people would not be able to select the size that want and get the print to be the way it should. I know that sending the files to Mpix and how they print there is probably not a  Lightroom issue, but i just want to make sure what i export from LR is going to work.
    Thanks

  • Why pixels are not corresponding to the size I want?

    Hello,
    Recently I've detected a problem in my Adobe Illustrator CS6.
    I open the software, define the art board area in pixels (I checked it at Preferences > Units), but when I export my images they become bigger than they are.
    Example:
    This is an image 10x10 pixels, exported at Photoshop (everything is ok here):
    This is an image 10x10 pixels, exported at Illustrator.... much bigger!
    Here it is the options chosen at preferences:
    And what appears in work area:
    Does anyone knows what is going on? What can I do to solve this?
    Please tell me something. This way is hard to work...
    Thanks in advance.
    Best regards,
    Inês Guilherme

    Maybe, just guessing here, the resolution set for the photoshop doc was 72 and the one for illustrator 300?
    No, no, no. There is no "resolution" setting for a native Illlustrator file like that for a raster image.
    When uisng a program like Illustrator, FORGET PROGRAMS LIKE PHOTOSHOP. They are entirely different things and you're just confusing yourself.
    Inês,
    In a program like Illustrator, the page rulers refer to real-world units of measure when the document is printed. A pixel is NOT a real-world unit of measure. Ask yourself 'How big is a pixel?' or 'How many pixels is it from Earth to its moon?' Those are nonsensical questions. A pixel can be any size, because a pixel is nothing but a color value. Thinking of pixels as distance is like thinking of colors as distance. How many colors is it from where you live to New York City?
    When you work in a program like Photoshop, you are basically working within a SINGLE RASTER IMAGE. That single raster image has a fixed number of pixels. That's why Photoshop's rulers can make sense when they are set to pixels; they are not using pixels as a measure of distance; they are using pixels as a COUNT of pixels.
    But when you work in a program like Illustrator, you are NOT working in a single raster image. You are working within a model of a region of physical measure (a page) which can contain vector-based paths (which have no pixels), vector-based text (which has no pixels) and any number of MULTIPLE raster images.
    Each of those MULTIPLE raster images on the page has its own independent number of pixels, and its own independent scale, AND its own independent position (which doesn't even have to correspond to any whole increment of the rulers; the sides of those raster images on the page may be positioned BETWEEN the "pixels" indicated on the rulers).
    So in a program like Illustrator, you can have an image which contains 225 pixels across (or any other number, and another image which contains 25 pixels across (or any other number). Both of those images may be scaled on the page to the same UNIT OF MEASURE dimension. For example, both of those images may be scaled to one inch in width. The rulers, if set to "Pixels" would indicate that they both "measure" 72 "Pixels" across. But they would still contain different numbers of pixels, regardless of how many "Pixels" Illustrator's rulers indicate they "measure".
    Now given those very basic differences between what you're actually doing in a program like Photoshop and what you're doing in a program like Illustrator, what can the page rulers in Illustrator possibly mean when they are set to "Pixels"? Illustrator's rulers ALWAYS refer to a real unit of MEASURE, not to a mere COUNT of "Pixels." So when Illustrator's rulers are labeled "Pixels" they still have to ACTUALLY correspond to some unit of real-world measure.
    And they do: When you set Illustrator's rulers to "Pixels" you are really setting them to "Points". A point is 1/72 of an inch.
    So when you have your rulers in Illustrator set to "Pixels" and you draw your 10 x 10 "pixel" square, you are really drawing a 10 x 10 POINT square. And assuming you drew it as a path, it has no pixels whatsoever. It doesn't become rasterized until you either invoke the Rasterize command, or until you export it to a raster format. When you export it as a raster image, the only way the resulting image will actually contain 10 x 10 pixels is if you export it at a resolution of 72 pixels per inch.
    In other words, because Illustrator's rulers ALWAYS assume a scale of 72 pixels per inch when it uses "Pixels" as a bogus unit of measure, then you have to specify 72 PPI at the time of export if you want the number of pixels in the resulting raster image to correspond to the bogus "number of pixels" indicated by Illustrator's rulers.
    JET

  • Firefox keeps asking me to update to Firefox 3.6.18 but when i click on it it wont download. I want firfox to never ask me to update again. It's annoying.

    Firefox keeps asking me to update to Firefox 3.6.18 but when i click on it it wont download properly. I want firefox to never ask me to update again. It's annoying.

    See:
    * [[Software Update Failed]]
    * http://kb.mozillazine.org/Software_Update (Software Update not working properly)
    Remove the files in the updates and updates\0 folder:
    Mac: /Applications/Firefox.app/updates

  • HT6058 How do i erase the notification about ios7 update it wont download and i want to erase the notification.

    My ios7 update wont download how do i make the notification go away

    It wont go away until you update. You can update from the iPhones settings over wifi or with iTunes on your computer, here's a guide:
    http://support.apple.com/kb/ht4623
    Note: Make sure you back up the iPhone before updating.

  • Following code wont work as i want it to??

    Im writing a program which involves drawing several different shapes on a JComponent like JPanel. Im calling paint method of the JPanel casting in an Graphics2D object.
    What i want is to be able to draw shapes on the JPanel and after some time i be able to add in more shapes to the JPanel.
    This is what ive got so far:
    import java.awt.*;
    import javax.swing.*;
    public class DrawingPanel extends JPanel {
           private Graphics2D g2;
           //constructor
           public DrawingPanel() {
                setBackground(Color.RED);
            * Draws a circle & line on board.
           public void drawMoreShape(){
                //Draws line
                g2.drawLine(30, 10, 24, 57);
                Ellipse2D.Double circle = new Ellipse2D.Double(20,60,30,30);
                g2.setColor(Color.BLUE);
                g2.fill(circle); //Draws a circle
                //Repaints the board...
                repaint();
            * @see javax.swing.JComponent#paint(java.awt.Graphics)
           public void paint(Graphics g) {
                  super.paint(g);
                  g2 = (Graphics2D) g;
                  g2.setColor(Color.BLACK);
                  g2.drawLine(10, 20, 14, 47);
                                        g2.drawString("Hello", 20,20);
    }                    I want to call the drawMoreShape method during later stages (by another class) so i can add in more shape after i've already drawn initial stuff (the stuff in paint).
    This JPanel will ofcourse be embedded inside a JFrame class which has all common swing features such as clicking a button("Add more shapes") which calls that method to add more shapes.
    But thats advanced and all i want now is to get the basic of drawing on JPanel & adding more drawings after ive initially drawn something involving the use of Graphics2D object.
    The only reason i can think so far is that g2 is null but i've initiated it in paint method.
    So can someone tell me whats wrong?
    Edited by: Theresonly1 on Jul 31, 2008 9:15 AM

    All drawing in Swing should be done in paintComponent function.This is not exactly 100% true. It is okay - in fact good code style - to pass the graphics object from paintComponent to sub-methods, so that you can compartmentalize your painting. Also, if you create an image buffer, you can draw to that from anywhere and just call repaint when your done.
    But basically this is right. I was just trying to get @OP up and running as quickly as possible
    If you're going to put everything in paintCOmponent, you need to have a boolean flag, like paint2ndPart. Then switch that on when you want to paint the second part.
    There is no meaning to drawing inside drawMoreShape and then calling repaint, since repaint will invoke a paint cycle which will delete it.
    Read the tutorial: [Performing Custom Painting|http://java.sun.com/docs/books/tutorial/uiswing/painting/]
    And this article: [Painting in AWT and Swing|http://java.sun.com/products/jfc/tsc/articles/painting/]

  • How do you print a photo in the size you want?

    I set the custom size as 5 x 3 and the photo printed 2-1/2 x 2. How do you set the photo size?

    There are 9 different versions of iPhoto and they run on 9 different versions of the Operating System. The tricks and tips for dealing with issues vary depending on the version of iPhoto and the version of the OS. So to get help you need to give as much information as you can. Include things like:
    - What version of iPhoto.
    - What version of the Operating System.
    - Details. As full a description of the problem as you can. For example, if you have a problem with exporting, then explain by describing how you are trying to export, and so on.
    - History: Is this going on long? Has anything been installed or deleted? - Are there error messages?
    - What steps have you tried already to solve the issue.
    - Anything unusual about your set up? Or how you use iPhoto?
    Anything else you can think of that might help someone understand the problem you have.

  • Wallpapers wont re size after updating to IOS 7

    After I updated my iphone 4s to IOS 7 . The wallpaper won't re size. It will stay as a huge photo.

    You are going to have to take in to your phone company, if the orginal sim will not work.

  • How can you have all pages open at the same display size, instead of having to hit Ctrl+ to get the size you want?

    In IE the page can either be set to 100% or whatever you wish, and once set future pages open up displayed the same way. With FF every time I open a page I have to hit ctrl+ about 3 or 4 times to get it to fill the screen
    I have tried changing the default font to 16 with a min of 16 and not letting the page decide etc. I am sure that this has been asked before, but I have not used FF in several years.
    Thanks

    There are some add-ons that can be used to change the zoom level on all sites, for example:
    * NoSquint - https://addons.mozilla.org/firefox/addon/nosquint/
    * Default FullZoom Level - https://addons.mozilla.org/firefox/addon/default-fullzoom-level/

  • How do I UNINSTALL my CS4(Vista) from my WIN 8 NEW PC? It wont INSTALL, and NOW wants me to PAY TO UPGRADE to UNINSTALL.

    I purchased CS4 back when. And I never had any problems running it on my laptop (Vista). I finally used up all my 250gb hard drive and my husband just bought me a new WIN 8 desktop. I tried INSTALLING using my CD but WIN 8 wouldnt allow me to install. Adobe said I had to PAY TO UPGRADE so that I could finish INSTALLING. Well NOW since I am unable to do so, I tried going to the CONTROL PANEL and UNINSTALLING. But Adobe REFUSES to UNINSTALL since I do not have the UPGRADE version to allow to do so.
    SO NOW.............I am unable to INSTALL my iCloud program or any other program because my WIN 8 is "currently installing Adobe" and refuses to allow me install another program or Uninstall Adobe.
    HELP!!!

    Current is the Cloud... several monthly/annual plans... stop paying and it stops working
    http://www.adobe.com/products/creativecloud/faq.html
    http://helpx.adobe.com/creative-cloud/help/install-apps.html to install or uninstall
    http://forums.adobe.com/community/download_install_setup/creative_cloud_faq
    what is http://helpx.adobe.com/creative-cloud/help/creative-cloud-desktop.html
    Cloud Getting Started https://helpx.adobe.com/creative-cloud/topics/getting-started.html
    About 2 years old (so no longer updated) is the perpetual license for CS6 for a one time cost Creative Suite 6

  • How do I find iBooks author file size? want to stay under 1gb.

    I am wondering if there is anything like Get Info for the iOS. May be obvious but I have not found it. TIA.

    Share/export as .ibooks file to where you can find it - then locate it in the Finder - Use the menu Get Info it is't now shown in the Finder window.
    You can also load it to iTunes and do a get info there as well.

  • I can't get the print sizes I want in iPhoto 6

    Got the new iMac about three weeks ago, and have installed iLife '06.
    I've just tried to print a photo out 4 x 6 and the preview shows the photo in the bottom right of the screen (which is how it used to be on iLife '04).
    However, when printed, the picture is just off centre of the A4 photographic paper and measures approximately 2 inches x 2.5 inches.
    It's the same if I try to print a 5 x 7 print. The resulting photo measures approx 2.5 inches x 3 inches.
    Why is this? Do I need to install drivers?
    When I print letters or web pages, everything is fine.
    I'm using an Epsom Stylus Photo R300 printer, by the way.
    Any help would be greatly appreciated.
    Many thanks.

    I find the iPhoto print drivers terrible and have
    given up trying to print directly from iPhoto. If you
    have PhotoShop, open up the image and print from
    PhotoShop. It has much better printer controls and
    has Color Correcting for adjusting the colors for
    most printers. I normally use the standard 1998
    embedded color profile for all my PhotoShop work.
    Hope it helps, Bill
    MacBook Pro Mac OS X (10.4.5)
    Unfortunately she does not have Photoshop. This seems like a serious flaw in Iphoto 6. Kinds of reminds me of Microsoft problems. There must be a solution. Yes?

Maybe you are looking for

  • Aperture 3.2.1 upgrade - - ok for me

    I upgraded to Aperture 3.2.1 from the most prior recent version.  Works ok for me.  No problems . . . yet.  I use a 2 x 2.66GHz Dual-Core Xeon with 7GB of 667 MHz RAM

  • Incorrect Source System name after System Copy

    Hello Friends,   When we copied Source system  from Production  to our  Qulaity  system,   the DTP s are still displaying Production Source system. We are in BI7.0 SP13 . I have run TC BDLS to convert Old Source system to new Source system. But still

  • Document windows in taskbar

    Version 8 allowed you to open multiple documents but only show one instance of Acrobat on the taskbar, rather than showing each document as a separate instance (though it wasn't enabled by default, you had to choose the option). Did they remove this

  • Change document to be opened on kBeforeOpenDocSignalResponderService

    Hello, I want to change the document being opened by InDesign within kBeforeOpenDocSignalResponderService. This means the user opens a document stored on a fileserver (over a slow network), and I want to copy this file to a local drive and then open

  • Toast 7.1 Media Browser-iPhotos Will Not Show

    Since purchasing Toast 7.1 none of my iPhotos will show in the Media Browser. My iMovies, iMusic and DVD do show. Ran Disk Warrior and TechTool-no problems. My iPhoto library is located in the correct location-user/Pictures/iPhoto library. I did a qu