Hi all,
Right now i’m working about an integration of a JMonkey application in a Swing Window and I am stuck by problem, First i created my Application. Next i created my Swing Window with all interface. And finally i made a class to manage interactions between the two.
[java 1=“language=”"""" language=""]package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class defaultEditorApp extends SimpleApplication {
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry(“Box”, b);
this.getFlyByCamera().setDragToRotate(true);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);
mat.setTexture(“m_ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
}[/java]
[java]
//The Swing window
package mygame;
import com.jme3.system.AppSettings;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class FenetreSwing extends JFrame
{
protected JMenuBar menuBar;
JPanel panel;
protected JMenu menuFile;
protected JMenu menuEdit;
protected JMenu menuView;
protected JMenu menuHelp;
protected JList assetList;
public FenetreSwing(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar();
JList();
JPanel();
this.add(panel);
}
private void JList(){
String[] selections = { “green”, “red”, “orange”, “dark blue” };
assetList = new JList(selections);
assetList.setVisibleRowCount(4);
assetList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private void JPanel(){
panel = new JPanel(new FlowLayout());
panel.add(new JScrollPane(assetList));
}
private void JMenuBar(){
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
menuFile = new JMenu(“File”);
menuBar.add(menuFile);
menuEdit = new JMenu(“Edit”);
menuBar.add(menuEdit);
menuView = new JMenu(“View”);
menuBar.add(menuView);
menuHelp = new JMenu(“Help”);
menuBar.add(menuHelp);
MenuFile();
}
public void MenuFile(){
JMenuItem itemNew = new JMenuItem(“New”);
menuFile.add(itemNew);
JMenuItem itemExit = new JMenuItem(“Exit”);
menuFile.add(itemExit);
}
}
[/java]
[java]
package mygame;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FenetrePrincipale
{
FenetreSwing window;
defaultEditorApp app;
private JmeCanvasContext context;
private Canvas canvas;
public FenetrePrincipale(){
window = new FenetreSwing();
app = new defaultEditorApp();
actionMenu();
createCanvas();
window.getContentPane().add(canvas);
app.startCanvas();
window.assetList.setLocation(650, 490);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
}
private void createCanvas(){
AppSettings settings = new AppSettings(true);
settings.setWidth(640);
settings.setHeight(480);
app.setPauseOnLostFocus(false);
app.setSettings(settings);
app.createCanvas();
context = (JmeCanvasContext) app.getContext();
canvas = context.getCanvas();
Dimension dim = new Dimension(640, 480);
canvas.setPreferredSize(dim);
}
private void actionMenu(){
window.menuFile.getItem(0).addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
window.getContentPane().remove(canvas);
app.destroy();
app = new defaultEditorApp();
createCanvas();
window.getContentPane().add(canvas);
//Refresh//
window.setVisible(false);
window.setVisible(true);
window.requestFocus();
}
});
window.menuFile.getItem(1).addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae) {
window.dispose();
app.stop();
}
});
}
}
[/java]
So the problem is that: 1°) My JList does not appear in my application ;
2°) The size of my canvas changes proportionally to the size of the window ;
Sorry for thisuseless post. My problem was just totally stupid…
I’ve done [java]window.getContentPane().add(canvas)[/java] whereas the correct thing was this [java]window.panel.add(canvas);[/java].