• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking for layout advice

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that monitors servers on our network.
It's main screen has a tabbed pane. On one of the panes I want to plot the response times of three different servers.

How can I get three canvases on a panel that I will place on the tabbed pane?



I don't know if that will display what I am trying to do or not.

Stated another way, there are three canvases placed in the CENTER of three panels. Those panels a placed in a parentPanel (NORTH, CENTER, and SOUTH). That parentPanel is then placed in the tabbedPane.

I'm running into a number of irritating problems and I was just looking here to see if anyone thinks this layout won't work, and if so, could you suggest another approach to displaying this data?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My first question would be, why do you have 3 canvas' on 3 JPanels that are placed on a parent JPanel. It seems like the 3 JPanels could just be omitted. They seem like an extra component you don't need?

With that being said, I'm not real clear yet on the layout you are needing. You seem to be using a BorderLayout and when putting components N, CENTER, and S, the center component will be larger than the N and S components.

If you just want to line up 3 components vertically, take a look at either a BoxLayout or GridLayout.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mention using canvases; I would use a JPanel instead of a Canvas — mixing Swing and AWT components can give undesirable results.

One of the problems of using a BorderLayout is that the North and South sections will need some component vertical size information to properly display your components. They expand the components to fill the horizontal space. This can get messy. If you know the height you want for the North and South components you can do

Assuming all three graphic components are to be the same size you could try GridLayout (as Gregg recommends above) or a GridBagLayout. Here's a demo of those two:
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GridLayout (3,2) seems to be yielding some better results.

It's also introduced some, but I think they are more easily explained here.

Check out this code fragment:


This is placing one of my canvases on the tabbedPane, but it has the side affect of making my button the same height as my canvas. Do I have to specifically set the size of that button to get around that problem?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GridLayout ignores the preferred size of the components you hand it and tries to display all of its components at the same size. To keep the button at its preferred size you can add it to a JPanel and add the JPanel to the GridLayout (or BorderLayout). The JPanel will expand to fill the grid cell and allow the JButton to remain at its preferred size. The general practice in Swing is to use the JComponent methods get/setPreferredSize in lieu of setSize.
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'll give the button on a Panel a try.

I've changed from Canvases to panels and that has also cleared up some of my problems.

I was seeing the canvases appear drawn overtop of other components and I was assuming that it must be happeneing because of the order in which I was creating the components.

However, like I said above, as soon as I switch to JPanels in place of the Canvases, that problem went away.

Thanks a lot, guys.
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic