Results 1 to 5 of 5
Thread: Setting up a frame
- 11-21-2010, 06:07 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Setting up a frame
Hello everyone,
As you can see this is my first post and i was just wondering how you set up a JFrame with contained components.
Basically i want to have them in this order:
Canvas BELONGS TO: DesktopFrame (JInternalFrame).
JInternalFrame (ifrmTools) BELONGS TO: DesktopFrame (JInternalFrame).
DesktopFrame (JInternalFrame) BELONGS TO: dpDesktop (DesktopPane).
dpDesktop (DesktopPane) BELONGS TO: frmMain (JFrame).
But if you didnt understand that then i will try to break it down.
Basically i want to have a JFrame, that on it, has a canvas and an internal frame called ifrmTools. I want the Tools frame (internal frame) to float over the canvas so they can pick a tool to draw on the canvas with. Like a simple PAINT program.
Here is my issue, i have code, but it wont show the InternalFrame that is called 'ifrmTools' however it shows the Canvas.
Below is my code:
Java Code:import java.awt.Canvas; import java.awt.Color; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; public class Create { private double currentVersion = 1.0; public JFrame frmMain = new JFrame("Welcome " + currentVersion); public JDesktopPane dpDesktop = new JDesktopPane(); public JInternalFrame ifrmDesktop = new JInternalFrame(); public JInternalFrame ifrmTools = new JInternalFrame("Tools"); public Canvas cCanvas = new Canvas(); public void createAll() { createAndAddCanvas(); createAndAddToolsFrame(); createAndAddDesktopFrame(); createAndAddDesktopPane(); createAndAddMainFrame(); } public void createAndAddCanvas() { cCanvas.setBackground(Color.WHITE); ifrmDesktop.add(cCanvas); } public void createAndAddToolsFrame() { ifrmTools.setResizable(false); ifrmTools.setBounds(10, 10, 105, 250); ifrmTools.setVisible(true); ifrmDesktop.add(ifrmTools); } public void createAndAddDesktopFrame() { ifrmDesktop.setResizable(false); ifrmDesktop.setBorder(null); ifrmDesktop.setClosable(false); ifrmDesktop.setMaximizable(true); ifrmDesktop.setVisible(true); dpDesktop.add(ifrmDesktop); } public void createAndAddDesktopPane() { dpDesktop.setVisible(true); frmMain.add(dpDesktop); } public void createAndAddMainFrame() { frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmMain.setSize(800, 600); frmMain.setLocation(100, 100); frmMain.setVisible(true); } }
Java Code:public class Main { public static void main(String[] args) { Create c = new Create(); c.createAll(); } }
Pencil.
-
You shouldn't mix AWT components with Swing components. So get rid of the Canvas and use a JFrame or similar instead. It does all that Canvas does and more. For your floating tools, why not just use a JToolBar?
e.g., toolbar tutorial
- 11-21-2010, 07:18 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Ok man cool, cheers for the advice i really appreciate it.
Just out of consideration, howcomes you shouldn't mix them?
Pencil.
- 11-21-2010, 11:33 AM #4
Mixing heavy and light components
You may also find this interesting
Painting in AWT and Swing
db
-
Similar Threads
-
Returning focus to a frame after hiding another frame
By fletcher in forum AWT / SwingReplies: 7Last Post: 11-02-2009, 07:31 PM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 05:37 PM -
GUI new frame
By billbo123 in forum New To JavaReplies: 15Last Post: 03-02-2009, 05:24 AM -
Setting the DSN
By tim in forum JDBCReplies: 1Last Post: 02-14-2008, 10:55 PM -
Help with setting up please
By BlitzA in forum New To JavaReplies: 6Last Post: 12-29-2007, 01:54 PM
Bookmarks