Created
May 27, 2010 18:05
-
-
Save jersub/416132 to your computer and use it in GitHub Desktop.
Displays a frame with a Processing applet fitting the frame borders, having palettes on top, but that are still under the menu bar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2010 Jérémy Subtil. All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are met: | |
* | |
* * Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* * Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* * Neither the name of the University of California, Berkeley nor the | |
* names of its contributors may be used to endorse or promote products | |
* derived from this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY | |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY | |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
package uitest; | |
import java.awt.BorderLayout; | |
import java.awt.Color; | |
import java.awt.Container; | |
import javax.swing.JFrame; | |
import javax.swing.JInternalFrame; | |
import javax.swing.JLayeredPane; | |
import javax.swing.JMenu; | |
import javax.swing.JMenuBar; | |
import javax.swing.JMenuItem; | |
import javax.swing.JPanel; | |
import javax.swing.JRootPane; | |
/** | |
* Displays a frame with a Processing applet fitting the frame borders, having | |
* palettes on top, but that are still under the menu bar. | |
* | |
* @author Jérémy Subtil <[email protected]> | |
* | |
* @see http://java.sun.com/javase/6/docs/api/javax/swing/JRootPane.html | |
* @see http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html#layeredpane | |
* @see http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html | |
* @see http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html | |
*/ | |
public class Main { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
new TestFrame(); | |
} | |
/** | |
* The test frame. | |
*/ | |
static class TestFrame extends JFrame { | |
public TestFrame() { | |
JRootPane contentRootPane = new JRootPane(); | |
setContentPane(contentRootPane); | |
Container contentPane = contentRootPane.getContentPane(); | |
contentPane.setLayout(new BorderLayout()); | |
JLayeredPane layeredPane = contentRootPane.getLayeredPane(); | |
JMenuBar menuBar = new JMenuBar(); | |
JMenu fileMenu = new JMenu("File"); | |
fileMenu.add(new JMenuItem("TEST 1")); | |
fileMenu.add(new JMenuItem("TEST 2")); | |
fileMenu.add(new JMenuItem("TEST 3")); | |
fileMenu.add(new JMenuItem("TEST 4")); | |
menuBar.add(fileMenu); | |
setJMenuBar(menuBar); | |
JPanel processingPreview = new JPanel(); | |
processingPreview.setBackground(Color.WHITE); | |
contentPane.add(processingPreview, BorderLayout.CENTER); | |
JInternalFrame intFrame = new JInternalFrame(); | |
layeredPane.add(intFrame, JLayeredPane.PALETTE_LAYER); | |
intFrame.setSize(100, 100); | |
intFrame.setVisible(true); | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
setSize(300, 300); | |
setVisible(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment