5

I would like to have a separate graphics window (along with a separate cartesian coordinate plane) inside a larger window using java.awt/javax.swing, I've drawn a picture to show you what I mean.

I have no idea how to do this, throwing some kind of literature at me that I can read to understand this better would be really great, a solution for my problem along with that would be awesome.

PS. I haven't really tried anything, as I have no idea what to try.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Johan
  • 605
  • 5
  • 16
  • 2
    You really should first go to the Swing tutorials and start reading. Read on JFrames, JPanels, and on drawing with Swing. That should give you some good ideas about where to start. You can find the tutorials as part of the Java tutorials: [The Really Big Index](http://docs.oracle.com/javase/tutorial/reallybigindex.html). Voting to close this question as being too broad and ambiguous for StackOverflow. – Hovercraft Full Of Eels Mar 08 '12 at 19:43
  • Someone mentioned using internal frames -- bad idea. Instead simply use a JPanel for drawing by overriding its paintComponent method, and place in your JPanel using appropriate layout managers, that's all. Again, the tutorials will explain all of this to you. – Hovercraft Full Of Eels Mar 08 '12 at 19:49
  • Great description (the diagram) BTW. A picture paints a thousand words, and that image is < 11Kb. :) – Andrew Thompson Mar 09 '12 at 05:22

3 Answers3

4

I recommend downloading NetBeans to start with, as it is the easiest IDE for UI design I know of.

  1. Start with creating the main frame of your application.
  2. Add all the buttons you need and position them as in your picture on the main frame.
  3. Add a JPanel to your frame and call it something like drawingCanvasPanel. This panel will be the drawing area. Don't forget to override the Panel's painComponent method in which you will draw your custom drawings and shapes using the panel's Graphics.
GETah
  • 20,922
  • 7
  • 61
  • 103
  • 3
    +1 for NetBeans. @Johan: Don't succumb to the allure of the GUI editor until you understand [layouts](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html). – trashgod Mar 08 '12 at 20:05
  • Sounds simple enough, I'll google around a little to find out more. @trashgod: Yeah, that's pretty much what I was gonna do anyway (using layouts). On the Netbeans advice: Thanks but I'll stay with Emacs, it's what I'm used to and it works good enough. – Johan Mar 08 '12 at 20:10
  • @Johan Glad it helped :) Good luck with Emacs, there is not better way to understand layouts other than playing around with raw layout code (instead of an IDE doing all the work for you :) ) – GETah Mar 08 '12 at 20:43
4

I'd override paintComponent() in a JPanel on the left, as discussed here. A JPanel of JButton in a BoxLayout could go on the right, as shown here. See also the related example, LinePanel.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
-1

You can use Internal Frames, for how to use it, see the official tutorial

  • No, this is most definitely not a situation where internal frames should be used. Nested JPanels yes, but there's no reason to create internal frames. – Hovercraft Full Of Eels Mar 08 '12 at 19:48
  • He wants a window inside another window, as far i know, internal frame do that. – Demetrio Neto Mar 08 '12 at 20:02
  • Sorry if you misunderstood, I wasn't looking for a window inside of a window (with close buttons and so on I mean), the other guys seem to have gotten what I meant. Thanks anyway! – Johan Mar 08 '12 at 20:06