Results 1 to 9 of 9
  1. #1
    greenhorn is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default AutoSizing of windows in GridBagLayout is not working

    I have placed 4 charts with JFreeChart in a grid layout, but the diagrams are not completly shown :eek:. Somehow there must be an autosizing option available to make sure the diagrams are auto-sized.
    I would appreciate any idea - Thanks :confused:

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    Do you use frame.pack() or frame.setSize()? You should be using pack() so that all components will be displayed at their preferred sizes.

  3. #3
    greenhorn is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    Thanks for the advise, but I cannot make it work. The construction I have is: Tabs --> GirdLayout --> Diagram.
    Java Code:
    // Creating the tab panel
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setPreferredSize(new Dimension(810, 550));
    ...
    // Creating the first tab
    JPanel panelMonth = new JPanel(new GridLayout(1, 2, 5, 5));
    panelMonth.setPreferredSize(new Dimension(1000, 650));
    ...
    // creating the diagram
    DashboardChart chartUpdated = new ChartPieUpdated();
    ...
    panelMonth.add(chartUpdated);
    I thought I would need to do chartUpdated.pack();, but this option is not availble. Or is there may be another 'add' contructor I can use for the last line code?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    panelMonth.setPreferredSize(new Dimension(1000, 650));
    Don't set the preferred size of your compnents. Each component is responsible for determining its own preferred size. The pack() should work properly.

    Or

  5. #5
    greenhorn is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    I guess the problem is, since the pack only works on Frames not on Panels. You (or anyone is welcome to) know how to expand this or to work around it?

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    There is no problem and there is nothing to work around. YOu add all you components to the frame and then pack() the frame. Its that simple. If it doesn't work you are doing something wrong.

    If you need more help then post your Short, Self Contained, Correct Example that demonstrates the problem. And don't post JFreeChart code since that is non standard code.

  7. #7
    greenhorn is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    Hello, here is the code I have and I hope that I gave everything, which is required to give you a good impression. Otherwise I am happy to share more code.
    Java Code:
    // ----- TAB CONFIGURATION -----
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setPreferredSize(new Dimension(810, 550));
    // --- TAB 1
    JPanel tab1 = new JPanel(new GridLayout(1, 2, 5, 5));
    tab1.setPreferredSize(new Dimension(1000, 650));
    tabbedPane.addTab("Tab1", iconLabelMonth, Tab 1, "Text");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
    // Chart in tab1
    DashboardChart chart = new ChartPie();
    tab1.add(chart);
    tab1.pack(); does not work, there is not such option available. Is there may be something else than new Dimension ... I can write?
    Thanks for your advise.

  8. #8
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    Have you even read my suggestions???

    In my second reply I specifically stated NOT to use setPreferredSize().

    I asked for a SSCCE. Did you read the link? How is that code compileable?

    I specifically mentioned not posting JFreeChart code. DashboardChart and ChartPie, sure like like non standard classes to me.
    Last edited by camickr; 04-15-2011 at 09:43 PM.

  9. #9
    greenhorn is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    Thanks for your input, we leave it than and I find other ways/solutions.

Similar Threads

  1. Replies: 1
    Last Post: 02-19-2011, 08:36 AM
  2. Replies: 1
    Last Post: 08-19-2010, 12:47 PM
  3. Gridbaglayout not working as expected
    By berkeleybross in forum AWT / Swing
    Replies: 7
    Last Post: 07-06-2010, 12:11 PM
  4. Eclipse debug not working on Windows Vista
    By mathew.vinay in forum Eclipse
    Replies: 5
    Last Post: 04-04-2009, 01:06 PM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •