JFrames and JMenus

i noticed something odd earlier.
The creation of a JMenu or Swing objects is not a problem.
The problem i encountered is:
Calling a class which extends JFrame which is in a separate file to the main method is kept.
The menu will appear, but will fail draw any of the components of the JMenu, this occurred until i placed the main method in the same file as the above mentioned class where it promptly worked?
could any one give me any explanation of what is happening? (or not as the case may be)

Is it possible that you code post a working example to show the problem? It is hard to debug, without it, unless someone has had the same exact problem.

Similar Messages

  • How can i hide a JFrame and then Show it again in runtime

    How can i hide a JFrame and then Show it again in runtime??
    Please, please help me
    Its URGENT

    Here's even an example:
    import javax.swing.*;
    public class HideAndShow extends JFrame
         public HideAndShow()
              super("Hello");
              setSize(200, 200);
              setVisible(true);
              try
                   Thread.sleep(2000);
              } catch(InterruptedException e) {}
              setVisible(false);
              try
                   Thread.sleep(2000);
              } catch(InterruptedException e) {}
              setVisible(true);
         public static void main(String[] args)
              new HideAndShow();
    The JFrame will show, then hide, then show again. This is at runtime.

  • JFrame and Windows as a whole

    Hey peoples,
    Anyone know where I can get information in regards to building custom windows? For example, the default Java Window has the Java Icon on the top right of the window and has a particular color to it. I was interested on making a window with a different border, color, (Top label)...you know, just customize the appearance...any clues?
    Thanx,
    Shrubz

    I'm building a standard application. I know how to use JFrame and the whole nine yards; however, I was looking into customizing the actual Window which is created by Swing. Let us say that the TOP bar which every window has by default is displaying a stretched image rather than the light blue color is has by default...know what I mean?
    Thanx,
    Shrubz

  • Enlarge JFrame and its components properties  proportionally

    Hi,
    We have a simple JFrame � Container - uses Flow Layout and has got Buttons, Text Fields� All of them are using Java�s default fonts, sizes..�
    And we want to increase or enlarge all of the JFrame and its sub components properties proportionally (especially Font�.) like in for example MS-Word.
    In the Ms-Word, there is ZOOM option in the Standard tool bar menu. If you set zoom to 150%, the font is automatically increases. And if you set it to 100% the font sets back to normal. And if the window is not enough to fit, it adds the scroll bars.
    For example, if we increase the Labels Font, the height of that component also should increase proportionally. So the Frame also should increase.
    How could we achieve this sort of functionality ( i.e. Proportionally increasing the component�s properties ) in Swing?
    I believe it is hard to set/adjust the all of the Frame�s components properties (I.e. Height, Font�) proportionally by using the Component listeners.
    (Another example, you might have noticed that the Frame�s Font, hight,width �sizes are proportionally bigger in Systems screen�s 800 by 600 pixels mode compare with 1024 by 768 pixels mode. May be this is windows feature. But we are looking at achieving the same sort of feature)
    Any help or thoughts would be appreciated.
    Thanks in advance.
    Vally.

    Here is a working sample:
    package ui_graphics;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.LayoutManager;
    import java.util.Arrays;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerListModel;
    import javax.swing.SpinnerModel;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    public class ZoomableFrameTest {
       private ZoomablePanel zoomPanel;
       private JLabel label;
       public ZoomableFrameTest() {
          label = new JLabel("Essai pour le zoom");
          label.setBounds(0,0,200,16);
          zoomPanel = new ZoomablePanel();
          zoomPanel.add(label);
          JFrame frame= new JFrame("Zoom test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(getZoomSpinner(), BorderLayout.NORTH);
          frame.getContentPane().add(zoomPanel, BorderLayout.CENTER);
          frame.pack();
          frame.setVisible(true);
       public static void main(String[] args) {
          new ZoomableFrameTest();
       public JSpinner getZoomSpinner() {
          String[] zoomValues = { "50", "100", "150" };
          SpinnerModel model = new SpinnerListModel(Arrays.asList(zoomValues));
          final JSpinner spZoom = new JSpinner(model);
          Dimension dim = new Dimension(60, 22);
          spZoom.setMinimumSize(dim);
          spZoom.setPreferredSize(dim);
          spZoom.setMaximumSize(dim);
          spZoom.setFocusable(false);
          spZoom.addChangeListener(new ChangeListener() {
             public void stateChanged(ChangeEvent e) {
                // R�cup�re le facteur d'�chelle
                int factor = Integer.parseInt((String)spZoom.getValue());
                setScaleFactor(factor);
          spZoom.setValue("100");
          return spZoom;
       private void setScaleFactor(int factor) {
          zoomPanel.setZoomFactor(factor);
    class ZoomablePanel extends JPanel {
       private int zoomFactor;
       public ZoomablePanel() {
          super(null);
       public void setZoomFactor(int factor) {
          this.zoomFactor = factor;
          if (this.isShowing()) this.repaint();
       public void paint(Graphics g) {
          super.paintComponent(g);
          double d = zoomFactor / 100d;
          Graphics2D g2 =(Graphics2D)g;
          g2.scale(d, d);
          super.paint(g2);
    }

  • Beginners Questions about Multiple JPanels in JFrame and event handling

    I am a newbie with SWING, and even a newerbie in Event Handling. So here goes.
    I am writing a maze program. I am placing a maze JPanel (MazePanel) at the center of a JFrame, and a JPanel of buttons (ButtonPanel) on the SOUTH pane. I want the buttons to be able to re-randomize the maze, solve the maze, and also ouput statistics (for percolation theory purposes). I have the backbone all done already, I am just creating the GUI now. I am just figuring out EventHandlers and such through the tutorials, but I have a question. I am adding an ActionListener to the buttons which are on the ButtonPanel which are on JFrame (SOUTH) Panel. But who do I make the ActionListener--Basically the one doing the work when the button is pressed. Do I make the JFrame the ActionListener or the MazePanel the ActionListener. I need something which has access to the maze data (the backbone), and which can call the Maze.randomize() function. I'm trying to make a good design and not just slop too.
    Also I was wondering if I do this
    JButton.addActionListener(MazePanel), and lets say public MazePanel implments ActionListenerdoesn't adding this whole big object to another object (namely the button actionlistener) seem really inefficient? And how does something that is nested in a JPanel on JFrame x get information from something nested in another JPanel on a JFrame x.
    Basically how is the Buttons going to talk to the maze when the maze is so far away?

    I'm not an expert, but here's what I'd do....
    You already have your business logic (the Maze classes), you said. I'm assuming you have some kind of public interface to this business logic. I would create a new class like "MazeGui" that extends JFrame, and then create the GUI using this class. Add buttons and panels as needed to get it to look the way you want. Then for each button that does a specific thing, add an anonymous ActionListener class to it and put whatever code you need inside the ActionListener that accesses the business logic classes and does what it needs to.
    This is the idea, though my code is totally unchecked and won't compile:
    import deadseasquirrels.mazestuff.*;
    public class MazeGui extends JFrame {
      JPanel buttonPanel = new JPanel();
      JPanel mazePanel = new JPanel();
      JButton randomizeB = new JButton();
      JButton solveB = new JButton();
      JButton statsB = new JButton();
      // create instanc(es) of your Maze business logic class(es)
      myMaze = new MazeClass();
      // add the components to the MazeGui content pane
      Component cp = getContentPane();
      cp.add(); // this doesn't do anything, but in your code you'd add
                // all of your components to the MazeGui's contentpane
      randomizeB.addActionListener(new ActionListener {
        void actionPerformed() {
          Maze newMaze = myMaze.getRandomMazeLayout();
          mazePanel.setContents(newMaze); // this is not a real method!
                                          // it's just to give you the idea
                                          // of how to manipulate the JPanel
                                          // representing your Maze diagram,
                                          // you will probably be changing a
                                          // subcomponent of the JPanel
      solveB.addActionListener(new ActionListener {
        void actionPerformed() {
          Solution mySolution = myMaze.getSolution();
          mazePanel.setContents(mySolution); // again, this is not a real
                                             // method but it shows you how
                                             // the ActionListener can
                                             // access your GUI
      // repeat with any other buttons you need
      public static void main(String[] args) {
        MazeGui mg = new MazeGui();
        mg.setVisible(true);
        // etc...
    }

  • Showing a JFrame and waiting for its closing

    Hi,
    I have to show a JFrame and wait until the user clicks OK button within the JFrame (therefore JFrame closes and continues program flow).
    Is there any method or trick to stop program's execution when JFrame.show() code is executed? Or do I have to wait in an infinite loop until a variable's value is changed?
    EXAMPLE:
    program code A;
    JFrame a;
    a.show(); // It must wait here
    // Executed after OK button in JFrame
    program code B;
    Thanks

    I spent quite a while trying to make a JFrame modal (or make a modal JDialog appear to be like a frame, by displaying it in the title in the win32 taskbar) the problem is, is that JFrame and JDialog are heavyweight components (that use native code) so I think it is a restriction of the Operating System and not Swing.
    This is what i have concluded anyway. If someone does know this to be incorrect and knows a way of doing this. I would also like to know, as it was one that i could find no perfect solution.
    Cheers
    wwe8

  • Disposing a jframe, and freeing up memory

    Greetings,
    I hope this is the proper forum for memory issues.
    I have an enterprise database reporting desktop application that I am developing. The GUI application reports on a huge set of data that results in the app taking up to 125 MB worth of memory when fully loaded. There are moments in using the application that all of the data will need to be refreshed entirely, and the JFrame that reports it be reloaded in the process.
    I am wondering how to dispose the JFrame and release all of the data associated with it. I use NetBeans to develop my GUI, and so all of the data that is needed for the JFrame is a class variable of the JFrame (so the data can be accessed as it is needed). But, when the frame is disposed, I no longer need anything associated with the JFrame that gets disposed. The Javadoc for Window.dispose() seems to imply that not all of the resources will be released and GC'd when you call dispose, because it says "The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show." which to me says that the data is being remembered and not collected by the GC.
    Anyone have any tips for GUIs and memory management? It seems like any GUI app could get pretty large pretty fast if there's no way to release the data associated with the GUI.
    Here's the code I've tested that doesn't seem to be releasing the memory (stress tests of closing and re-opening the window multiple times shows the java.exe process eating more and more memory):
        public void reset(){
            this.dispose();
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new PartsDashboard(partNum, dateFrom, dateTo);
            try{
                this.finalize();
            } catch (Throwable t){
                t.printStackTrace();
        }Thanks in advance.

    Three things you can always count on in life: Death, Taxes, and AndrewThompson64 telling people to post an SSCCE. =)
    Just poking fun.
    Anyways, this problem has gone from probably-should-deal-with-soon to critical issue. Here is the SSCCE to illustrate the problem. NOTE: My client is using Windows and I am using Windows, so how this acts on Linux/Mac isn't important to me. Also, a few of my client's machines are not well equipped (512 MB RAM), so they have agreed to up their hardware a bit.
    But the big problem, on my end, is that disposed windows DO NOT free up resources once disposed. My program is very data-heavy. I have considered grabbing less data from the database but this would mean the program would have to go to the database more often. The ultimate dilemma of time vs space, essentially.
    To explain the SSCCE: There is a main window with a button. If you click the button, it launches another window with a String array that is 500,000 items large (to simulate a lot of data), and a JList to view those strings. Closing the data-heavy child window does not free up the memory that it uses, and if you launch a bunch of the child windows in the same program instance (close each child before launching a new one) then you will see the amount of memory piling up.
    Am I doing something wrong? Has anyone else experienced similar problems? Does anyone have suggestions? Thank you.
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    * @author Ryan
    public class MemoryLeak {
        public static void main(String[] args) {
            // Launch Base Frame
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new BaseFrame().setVisible(true);
    class BaseFrame extends JFrame{
        public BaseFrame() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setPreferredSize(new Dimension(300,300));
            JPanel panel = new JPanel();
            panel.setLayout(new FlowLayout(FlowLayout.CENTER, 150, 5));
            JButton button = new JButton("Launch Data-Heavy Child");
            // JButton will launch Child Frame
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            // Notice no references to ChildFrame, period.
                            new ChildFrame().setVisible(true);
            panel.add(button);
            add(panel);
            pack();
    class ChildFrame extends JFrame{
        public ChildFrame() {
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setPreferredSize(new Dimension(300,600));
            JPanel panel = new JPanel();
            panel.setLayout(new FlowLayout());
            // Simulate lots of data.
            String[] dataArr = new String[500000];
            for(int i = 0; i < dataArr.length; i++) {
                dataArr[i] = "This is # " + i;
            // Something to display the data.
            JList list = new JList(dataArr);
            JScrollPane scrollPane = new JScrollPane(list);
            scrollPane.setPreferredSize(new Dimension(200, 550));
            panel.add(scrollPane);
            add(panel);
            pack();
    }

  • Resizing JFrames and JPanels !!!

    Hi Experts,
    I had one JFrame in which there are three objects, these objects are of those classes which extends JPanel. So, in short in one JFrame there are three JPanels.
    My all JPanels using GridBagLayout and JFrame also using same. When I resize my JFrame ,it also resize my all objects.
    My Problem is how should i allow user to resize JPanels in JFrame also?? and if user is resizing one JPanel than other should adjust according to new size ...
    Plese guide me, how should i do this ...
    Thanknig Java Community,
    Dhwanit Shah

    Hey there, thanx for your kind intereset.
    Here is sample code .
    In which there is JFrame, JPanel and in JPanel ther is one JButton.Jpanel is added to JFrame.
    I want to resize JPanel within JFrame,I am able to do resize JFrame and JPanel sets accroding to it.
    import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class FramePanel extends JFrame {
    JPanel contentPane;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    public FramePanel() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    FramePanel framePanel = new FramePanel();
    private void jbInit() throws Exception {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(gridBagLayout1);
    this.setSize(new Dimension(296, 284));
    this.setTitle("Frame and Panel Together");
    MyPanel myPanel = new MyPanel();
    this.getContentPane().add(myPanel);
    this.setVisible(true);
    class MyPanel extends JPanel {
    public MyPanel() {
    this.setSize(200,200);
    this.setLayout(new FlowLayout());
    this.setBackground(Color.black);
    this.setVisible(true);
    this.add(new JButton("Dhwanit Shah"));
    I think i might explained my problem
    Dhwanit Shah
    [email protected]

  • How to ZOOM the JFrame and its components ?

    Hi
    I could not find any solution/suggestions for this, so I am asking help.
    I am adding multiple components (JLables, JtextFields and a JTable) in to Jpanel(s) and to a JFrame window and I want to add Zoom (+ or - ) functions.
    I don't want to take each and every component from JFrame/ JPanel(s) and resize or repaint.
    Is there any way, that you can increase and decrease the whole JFrame and JPanel's view so that the components, which are been added to them, look like their sizes are also increased / decreased?
    Any suggestions or help would be appreciated.
    Thanks.
    Regards,
    Vally.

    ok...
    god bless the "GlassPane"
    you can take a snapShot of your frame...
    draw it on your glassPane..
    and just use your glassPane
    to paint the image with the requested size...
    in this approach you cant press a button and to things..
    shay

  • Inserting a Gui program using JFrames and JPanel

    I'm trying to insert a chat program into a game that I've created! The chat program is using JFrames and JPanels. I want to insert this into a GridLayout and Panel. How can I go about doing this?

    whatever is in the frame's contentPane now, you add to a separate JPanel.
    you also add your chat stuff to the separate panel
    the separate panel is added to the frame as the content pane

  • What is the difference between JFrame and JDialog?

    Is there any difference between JFrame and JDialog except that the JDialog can be modal?
    Is there any reason to use JFrame at all if i can achive the exactly the same with a JDialog?

    API wise they are basically the same, but they are usually built on top of different heavyweight components. Some platforms treat frames quite a bit differently than they do dialogs.

  • Difference between JFrame and JApplet

    i would like to create a GUI using java. as what i know, either i can use the normal applet or java swing. may i know what is the difference between 2 of them??
    thanks

    Hello thanku,
    You have asked two completely different questions:
    1) What is the difference between JFrame and JApplet?
    2) What is the difference between Applet and JApplet?
    A Java applet is a program that adheres to a set of conventions that allows it to run within a Java-compatible browser. To create a Java applet you may either use Applet or JApplet. If you are not running with in a browser, that is, if you are creating an application, you need to use a Frame or JFrame.
    Applet is the old way of creating a Java applet. It is better to use JApplet, since JApplet has all the functionality of Applet and more. Please note that you should not mix AWT components with Swing components.
    -Merwyn,
    Developer Technical Support,
    http://www.sun.com/developers/support.

  • JPopupMenu out side of JFrame and minimized will not close

    If you got a JFrame, and a popup menu that is partialy outside of the frame, and you minimize the frame, then open it again, the popup menu cant seem to close, like it dose if its entirely inside the JFrame. Any way to fix this?

    It seems that a mouseclickhandler(responsable for cleaning up the popupmenu)dose not respond when the mouse clicks on minimize. To fix this im just gona have an actionlistener set the popupmenu to not visable when its JFrame minimizes. If you can think of a better way tho...

  • Problem with JFrame and busy/wait Cursor

    Hi -- I'm trying to set a JFrame's cursor to be the busy cursor,
    for the duration of some operation (usually just a few seconds).
    I can get it to work in some situations, but not others.
    Timing does seem to be an issue.
    There are thousands of posts on the BugParade, but
    in general Sun indicates this is not a bug. I just need
    a work-around.
    I've written a test program below to demonstrate the problem.
    I have the problem on Solaris, running with both J2SE 1.3 and 1.4.
    I have not tested on Windows yet.
    When you run the following code, three JFrames will be opened,
    each with the same 5 buttons. The first "F1" listens to its own
    buttons, and works fine. The other two (F2 and F3) listen
    to each other's buttons.
    The "BUSY" button simply sets the cursor on its listener
    to the busy cursor. The "DONE" button sets it to the
    default cursor. These work fine.
    The "SLEEP" button sets the cursor, sleeps for 3 seconds,
    and sets it back. This does not work.
    The "INVOKE LATER" button does the same thing,
    except is uses invokeLater to sleep and set the
    cursor back. This also does not work.
    The "DELAY" button sleeps for 3 seconds (giving you
    time to move the mouse into the other (listerner's)
    window, and then it behaves just like the "SLEEP"
    button. This works.
    Any ideas would be appreciated, thanks.
    -J
    import java.awt.BorderLayout;
    import java.awt.Cursor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class BusyFrameTest implements ActionListener
    private static Cursor busy = Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR);
    private static Cursor done = Cursor.getDefaultCursor();
    JFrame frame;
    JButton[] buttons;
    public BusyFrameTest (String title)
    frame = new JFrame (title);
    buttons = new JButton[5];
    buttons[0] = new JButton ("BUSY");
    buttons[1] = new JButton ("DONE");
    buttons[2] = new JButton ("SLEEP");
    buttons[3] = new JButton ("INVOKE LATER");
    buttons[4] = new JButton ("DELAY");
    JPanel buttonPanel = new JPanel();
    for (int i = 0; i < buttons.length; i++)
    buttonPanel.add (buttons);
    frame.getContentPane().add (buttonPanel);
    frame.pack();
    frame.setVisible (true);
    public void addListeners (ActionListener listener)
    for (int i = 0; i < buttons.length; i++)
    buttons[i].addActionListener (listener);
    public void actionPerformed (ActionEvent e)
    System.out.print (frame.getTitle() + ": " + e.getActionCommand());
    if (e.getActionCommand().equals ("BUSY"))
    frame.setCursor (busy);
    else if (e.getActionCommand().equals ("DONE"))
    frame.setCursor (done);
    else if (e.getActionCommand().equals ("SLEEP"))
    frame.setCursor (busy);
    try { Thread.sleep (3000); } catch (Exception ex) { }
    frame.setCursor (done);
    System.out.print (" finished");
    else if (e.getActionCommand().equals ("INVOKE LATER"))
    frame.setCursor (busy);
    SwingUtilities.invokeLater (thread);
    else if (e.getActionCommand().equals ("DELAY"))
    try { Thread.sleep (3000); } catch (Exception ex) { }
    frame.setCursor (busy);
    try { Thread.sleep (3000); } catch (Exception ex) { }
    frame.setCursor (done);
    System.out.print (" finished");
    System.out.println();
    Runnable thread = new Runnable()
    public void run()
    try { Thread.sleep (3000); } catch (Exception ex) { }
    frame.setCursor (done);
    System.out.println (" finished");
    public static void main (String[] args)
    BusyFrameTest f1 = new BusyFrameTest ("F1");
    f1.addListeners (f1);
    BusyFrameTest f2 = new BusyFrameTest ("F2");
    BusyFrameTest f3 = new BusyFrameTest ("F3");
    f2.addListeners (f3); // 2 listens to 3
    f3.addListeners (f2); // 3 listens to 2

    I've had the same problems with cursors and repaints in a swing application, and I was thinking of if I could use invokeLater, but I never got that far with it.
    I still believe you would need a thread for the time consuming task, and that invokeLater is something you only need to use in a thread different from the event thread.

  • JFrames and Java3D simple problem

    Hi ive created a program using jframes in Java and im wanting to move it over to java 3d but im having problems. Ive litterally just looked at java 3d so my knowledge is limited. All i want is to set up my canvas so that i have a Jframe panel on the right and a 3d ball on the left. Here's my failed attempt......
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.image.*;//imports image functions
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.awt.*;
    public class Prog extends JFrame
        private Canvas3D canvas;
        private SimpleUniverse universe = new SimpleUniverse();  // Create the universe      
        private BranchGroup group = new BranchGroup(); // Create a structure to contain objects
        private Bounds bounds;
        public Prog()
            super("Program");
            GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
            canvas = new Canvas3D(config);
            //getContentPane().setLayout( new BorderLayout( ) );
            //getContentPane().add(canvas, "Center");
            Container c = getContentPane();
            setSize(600,400);
            c.setLayout(new BorderLayout( ));
            JPanel leftPanel = new JPanel( );
            leftPanel.setBackground(Color.BLACK);
            c.add(leftPanel, BorderLayout.CENTER);
            c.setLayout(new BorderLayout( ));
            JPanel rightPanel = new JPanel( );
            rightPanel.setBackground(Color.GRAY);
            c.add(rightPanel, BorderLayout.EAST);
            JButton goButton = new JButton("  Go  ");
            goButton.setBackground(Color.RED);
            rightPanel.add(goButton);
         Light();//Creates A Light Source
           // Create a ball and add it to the group of objects
           Sphere sphere = new Sphere(0.5f);
           group.addChild(sphere);
           // look towards the ball
           universe.getViewingPlatform().setNominalViewingTransform();
           // add the group of objects to the Universe
           universe.addBranchGraph(group);
        public void Light()
            // Create a white light that shines for 100m from the origin
            Color3f light1Color = new Color3f(1.8f, 1.8f, 1.8f);
           BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
            Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
           DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
            light1.setInfluencingBounds(bounds);
           group.addChild(light1);
        public static void main(String[] args)
           Prog frame = new Prog();
         frame.setVisible(true);
    }It Compiles but the 3d ball and the Jframe gui are in different windows but i want them in the same window but i duno how ?

    Hi tesla66 I'm sorry if I didn't correct your code, but drop some new code trying to solve the problem. I've used the cube instead the sphere because it's easier to see is rotating but just change "new ColorCube(0.4f)" with " new Sphere( 0.4f )". I wrote even some coments tought they're helpful. Tell me if I solved the problem
    import java.awt.*;
    import javax.swing.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import com.sun.j3d.utils.geometry.*;
    public class JFrameAndCanvas3D extends JFrame
         private Canvas3D canvas3D;
         public static void main(String[] args)
            new JFrameAndCanvas3D();
         public JFrameAndCanvas3D()
              initialize();
        public BranchGroup createSceneGraph()
            BranchGroup objRoot = new BranchGroup(); //root
            // Creates a bounds for lights and interpolator
            BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
            //Ambient light
            Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
            AmbientLight ambientLight = new AmbientLight(ambientColour);
            ambientLight.setInfluencingBounds(bounds);
            objRoot.addChild(ambientLight);
            ///Creates a group for transforms
            TransformGroup objMove = new TransformGroup();
            //You must set the capability bit to allow to write transform on the object
            objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
            //Adds a color cube
            objMove.addChild(new ColorCube(0.4));
            //Creates a timer
            Alpha rotationAlpha = new Alpha(-1, //-1 = infinite loop
                                            4000 // rotation time in ms
            //creates a transform 3D based on Y axis roation
            Transform3D t3d = new Transform3D();
            t3d.rotY(Math.PI/2);
            //Creates an rotation interpolator with an alpha and a TransformGroup
            RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objMove);
            rotator.setTransformAxis(t3d);//setta l'asse di rotazione
            //sets a bounding region. withouth this scheduling bounds the interpolator won't work
            rotator.setSchedulingBounds(bounds);
            //add the interpolator to the group
            objMove.addChild(rotator);
            //Adding the group to the root
            objRoot.addChild(objMove);
            objRoot.compile();//improve the performance
            return objRoot;
        public void initialize()
            setSize(800, 600);
            setLayout(new BorderLayout());
            GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();//default config
            canvas3D = new Canvas3D(config);
            canvas3D.setSize(400, 600);
            add(canvas3D, BorderLayout.WEST); //adding the canvas to the west side of the JFrame
            SimpleUniverse simpleU = new SimpleUniverse( canvas3D );
            JPanel controlPanel = new JPanel();
            controlPanel.setLayout(new BorderLayout());
            controlPanel.setSize(400, 600);
            JLabel label = new JLabel();
            label.setText("I'm the control Panel");
            controlPanel.add(label, BorderLayout.CENTER);
            add(controlPanel, BorderLayout.EAST);
            //Positioning the view
            TransformGroup viewingPlatformGroup = simpleU.getViewingPlatform().getViewPlatformTransform();
            Transform3D t3d = new Transform3D();
            t3d.setTranslation(new Vector3f(0, 0, 3)); //moving back from the cube--> +z
            viewingPlatformGroup.setTransform(t3d);
            canvas3D.getView().setBackClipDistance(300.0d); //sets the visible distance
            canvas3D.getView().setFrontClipDistance(0.1d);
            canvas3D.getView().setMinimumFrameCycleTime(20); //minimum time refresh
            canvas3D.getView().setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY); //rendering order
            BranchGroup scene = createSceneGraph();
            simpleU.addBranchGraph(scene);
            setVisible(true);
    }-->Davil

Maybe you are looking for

  • Is it possible to delete the records from LIS Table S601

    We have created some errorneous/unwanted  records in planning in table S601. Is there a way to delete these enties by Plant or material. Need your help urgently.. Please help. Thanks in Advance Rajesh

  • From which table i can get all activities ?

    I can get all active processes use below sql, select * from fuego_depproc a where a.fuego_status != 'D', but i don't know from which table i can get all activities of each process, who can tell me ? thanks.

  • Preventing a pop-up from closing

    Hi All, I've written a pop-up with an input box. I'd like to prevent the  pop-up from closing if the user hasn't entered anything in the input box. I open the popup from one view via the code:   DATA: l_cmp_api           TYPE REF TO if_wd_component,

  • How to add Google Page Rank bar to Firefox

    How to add Google Page Rank bar to Firefox? With Chrome I can add an extension but how to do this with FireFox? Please give me the simplest and easiest solution.

  • Render question - problem

    Hi, I am having some kind of problem when rendering.  Basically sometimes the look I apply simply doesn't render.  I can try again and again and nothing.  Then I try and it works.  What am I doing wrong?  It's totally, seemingly, hit or miss whether