• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel

 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem concerning JPanels. I have a JFrame, where i want to add several JPanels. I tried 2 things: first: I tried having a main panel, where i add all the other panels. But this does not work, because i cannot modify the position of the JComponents that i add on the other JPanels. second: I tried to add the panels individually, but at the first panel that i added i could not set the dimension on the screen, because it automatically set it to occupy the whole screen. How can i have a JFrame, with more panels, whose coordinates i can set manually, and also the coordinates of the JComponents that i add to them can be set manually?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to set coordinates of a component manually, then you have to call setLayout(null) on the container in which the component is placed. With no LayoutManager in place, the coordinates won't be set automatically, and any values you set will stay, unchanged.

Of course, if your window is resized, or if font sizes or look-and-feel vary on different platforms, then the components won't automatically adjust -- you'll have to handle that sort of thing manually. For this reason, using a null LayoutManager is generally considered to be a bad practice.
 
Rus Corina
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is look-and-feel? I see that a lot
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wiki
Oracle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!