1

how to set frame bounds in such a way that it occupies the entire region of the window ? I tried doing

Frame f=new Frame();
f.setBounds(0,0,Window.WIDTH,Window.Height)

but this code makes the frame go up and i cannot view the title bar..Please help me with this

maddy
  • 109
  • 4
  • 13
  • 1
    whats the `Window`, for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, just about emtpy `JFrame` & `Window???` – mKorbel Dec 31 '12 at 08:36
  • its like i want the frame to be of that size which appears when we maximize the frame or window as u say...for e.g.when we click on "My Computer" we get a small window initialy and later when we click on "maximize button" we see the entire "My Computer" frame/window ..I want my frame bounds in such a way that they appeared maximize.its difficult to explain – maddy Dec 31 '12 at 08:42
  • 1
    http://stackoverflow.com/questions/10123735/get-effective-screen-size-from-java That shows how to get real screen size and subtract taskbar space – StanislavL Dec 31 '12 at 10:33

3 Answers3

2

Try using setExtendedState (int state) with MAXIMIZED_BOTH state.

Azodious
  • 13,752
  • 1
  • 36
  • 71
  • i tried using this setExtendedState(MAXIMIZED_BOTH); but the frame goes up..i want the frame start from 0,0 pixel..Please can you help me further with this – maddy Dec 31 '12 at 08:50
  • What do you mean *"frame goes up"*? – MadProgrammer Dec 31 '12 at 09:03
  • The frame goes up means i m not able to see the title bar .so when i click at the bottom line of frame then only i m able to drag the frame so that the start location of frame is at 0,0 pixel – maddy Dec 31 '12 at 11:24
2
public static void main(String[] args) {
    JFrame frame = new JFrame();

    Dimension min = new Dimension(500,500);
    frame.setMinimumSize(min);

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension max = toolkit.getScreenSize();
    frame.setMaximumSize(max);

    frame.setVisible(true);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

Try this code . Its works the same way you wrote on comment above.

Achintya Jha
  • 12,735
  • 2
  • 27
  • 39
0

Try this code:

Frame f=new Frame();
f.setBounds(0, 0, Window.HEIGHT,Window.WIDTH);
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
Rajshri
  • 4,163
  • 2
  • 15
  • 17