1

Right now, I have a full screen application which spawns several full screen JFrames based on a configuration file (so I can never predict exactly how many frames I will have). These JFrames are in full-screen mode, like this:

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setUndecorated(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0,0,screenSize.width, screenSize.height);

The problem is, these JFrames are misbehaving in a Linux environment. I struggled a whole lot with requestFocus, requestFocusInWindow, toFront, setVisible, etc. But nothing seems to get it to work properly in Linux. The issue lies in the fact that I have several frames and I need to be able to switch between them when I click on a button (it's basically a menu).

So I'm starting to think a JFrame isn't the best object to use. Would it be easier to manager multiple frames if they were, say optionPanes? Or something similar? Whatever the solution, I need to be able to DO_NOTHING_ON_CLOSE and setUndecorated (or something similar).

Note: If you don't see a reason I need to change my JFrame and would know how I can switch focus/view easily, please let me know. This would also be an answer to my problem.

  • 3
    Why multiple JFrames and not a single JFrame with multiple views via CardLayout or something similar? – Hovercraft Full Of Eels Aug 16 '11 at 13:14
  • @Hovercraft: I'm not sure how CardLayout could solve my problem. Maybe I'm not seeing what you're trying to say. Currently on my JFrames im not using a LayoutManager as my application is based around being able to place using absolute positioning. –  Aug 16 '11 at 13:15
  • You could use a `JFrame` which contains a `JTabbedPane`, where each tab (a `JPanel` for example) has the current frame info. It's onlyu a possibility, maybe there are best solutions. If you prefer layouts, a `CardLayout` would be the best choice – Charliemops Aug 16 '11 at 13:16
  • @TheCharliemops: I'd rather not use a tabbed pane because I can never forsee how many frames a user will define in their configuration file. Image running this application in a small-screen environment and the user needs 15+ JPanels. This would mega-clutter the screen. –  Aug 16 '11 at 13:18
  • Take another look at [CardLayout](http://download.oracle.com/javase/tutorial/uiswing/layout/card.html) as suggested by @Hovercraft. It's not the kind of layout you are used to: each card can be a fullscreen panel and you can flip between them. – toto2 Aug 16 '11 at 13:46
  • @toto, I'm giving it a try. I'll take today to change my code to make it work with a card layout and I'll see if it works. –  Aug 16 '11 at 13:51
  • @MaxMackie I agree you. If the application has a high number of panels, a JTabbedPane is a bad solution. Then, try the CardLayout with fullscreen panels and buttons to switch them – Charliemops Aug 16 '11 at 13:57
  • @TheCharliemops: I'm trying that right now. However, wrapping my head around HOW a card layout works is proving challenging :) I'm new to JPanels and LayoutManagers so this is a task. –  Aug 16 '11 at 14:15
  • CardLayout worked like a charm! Thanks to all. Whoever can get that in an answer, I'll accept it. –  Aug 16 '11 at 16:15
  • 1
    Related examples [here](http://stackoverflow.com/questions/5654926/implementing-back-forward-buttons-in-swing/5655843#5655843) and [here](http://stackoverflow.com/questions/6432170/how-to-change-ui-depending-on-combo-box-selection/6432291#6432291). – trashgod Aug 16 '11 at 16:58

2 Answers2

1

i dont see your call to set the screen to fullscreen ?

http://download.oracle.com/javase/tutorial/extra/fullscreen/exclusivemode.html

Peter
  • 5,728
  • 20
  • 23
  • I had issues with full screen exclusive mode because it depends on the graphics card in the computer. And I'm trying to keep this as cross platform as possible. Thats why I simply grab the size of the screen and set the window to be that size. The remove all decorations. –  Aug 16 '11 at 13:20
1

I have decided to use the cardLayout and changing my code around a little bit.