• 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

How to create a flexible window?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have a window (jframe) with some components. Theres a JTextArea in a JScrollPane, some JButtons, a JMenuBar and some JLabels.
My problem is that when i show the window on other os than mine, the proportion of each component changed. Because i've worked width fixed
sizes for each component, i get the problem with the proportion of the components.
Now i want to create component which have relative sizes to the window, example jscrollpane.setPreferredSite(new Dimension(windowWidth - 10, windowHeight - 50)).
But i'm not sure that it is the right way. I found in the API the method getInsets() for JFrame
but whenn i used it, i get for ((Insets)myWindow.getInsets()).left 0.
Is there a possibility to get the Dimensions of the JFrame including the border, title an menu?
Greetx
Lars
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should use a LayoutManager and define relations between the sizes of your components. For example: JScrollpane should fill the lower half of the frame, if the frame gets resized the scrollpane should grow and shrink the other components shouldn't.
You can specify the empty space between the components using the layout manager.
My recommendation use GridBagLayout.
See the Swing Tutorial on Layout Managers.
 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I also use the GridBagLayout but I still have problems with it.
For example when I use a JEditorPane in a JScrollPane and I don't specify the size of the JScrollPane (with setPreferredSize, setMaximumSize, setMinimumSize) it collapses.
Do you know a possibility?
Regards
Lars
reply
    Bookmark Topic Watch Topic
  • New Topic