Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a flexible window?

 
Lars Tode
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic