我有一个名为" KinectViewer"我希望内容(或框架)出现在JSplitPane内的JScrollPane内部。但是,尽管我试图将KinectViewer中的JPanel添加到ScrollPane或试图将整个类本身带入其中,但我似乎无法解决这个问题。我似乎也无法在网上找到这样的东西。
这是KinectViewer:
package skeleton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import edu.ufl.digitalworlds.gui.DWApp;
@SuppressWarnings("serial")
public class KinectViewer extends DWApp implements ChangeListener
{
Kinect myKinect;
ViewerPanel3D main_panel;
JSlider elevation_angle;
JCheckBox near_mode;
JCheckBox seated_skeleton;
JCheckBox track_skeleton;
JButton turn_off;
JComboBox depth_resolution;
JComboBox video_resolution;
JCheckBox show_video;
JCheckBox mask_players;
JLabel accelerometer;
public void GUIsetup(JPanel p_root) {
setLoadingProgress("Intitializing Kinect...",20);
myKinect=new Kinect();
if(myKinect.start(true,Kinect.NUI_IMAGE_RESOLUTION_320x240,Kinect.NUI_IMAGE_RESOLUTION_640x480)==0)
{
DWApp.showErrorDialog("ERROR", "<html><center><br>ERROR: The Kinect device could not be initialized.<br><br>1. Check if the Microsoft's Kinect SDK was succesfully installed on this computer.<br> 2. Check if the Kinect is plugged into a power outlet.<br>3. Check if the Kinect is connected to a USB port of this computer.</center>");
//System.exit(0);
}
myKinect.computeUV(true);
near_mode=new JCheckBox("Near mode");
near_mode.addActionListener(this);
seated_skeleton=new JCheckBox("Seated skeleton");
seated_skeleton.addActionListener(this);
elevation_angle=new JSlider();
elevation_angle.setMinimum(-27);
elevation_angle.setMaximum(27);
elevation_angle.setValue((int)myKinect.getElevationAngle());
elevation_angle.setToolTipText("Elevation Angle ("+elevation_angle.getValue()+" degrees)");
elevation_angle.addChangeListener(this);
turn_off=new JButton("Turn off");
turn_off.addActionListener(this);
depth_resolution=new JComboBox();
depth_resolution.addItem("80x60");
depth_resolution.addItem("320x240");
depth_resolution.addItem("640x480");
depth_resolution.setSelectedIndex(1);
depth_resolution.addActionListener(this);
video_resolution=new JComboBox();
video_resolution.addItem("640x480");
video_resolution.addItem("1280x960");
video_resolution.setSelectedIndex(0);
video_resolution.addActionListener(this);
track_skeleton=new JCheckBox("Track Skeletons");
track_skeleton.setSelected(true);
track_skeleton.addActionListener(this);
show_video=new JCheckBox("Show video");
show_video.setSelected(true);
show_video.addActionListener(this);
mask_players=new JCheckBox("Mask Players");
mask_players.setSelected(false);
mask_players.addActionListener(this);
JPanel controls=new JPanel(new GridLayout(0,6));
controls.add(new JLabel("Depth Stream:"));
controls.add(depth_resolution);
controls.add(near_mode);
controls.add(new JLabel("Video Stream:"));
controls.add(video_resolution);
controls.add(show_video);
controls.add(new JLabel("Skeleton Stream:"));
controls.add(track_skeleton);
controls.add(seated_skeleton);
controls.add(mask_players);
accelerometer=new JLabel("0,0,0");
controls.add(accelerometer);
controls.add(elevation_angle);
//controls.add(turn_off);
setLoadingProgress("Intitializing OpenGL...",60);
main_panel=new ViewerPanel3D();
myKinect.setViewer(main_panel);
myKinect.setLabel(accelerometer);
p_root.add(main_panel, BorderLayout.CENTER);
p_root.add(controls, BorderLayout.SOUTH);
}
public void GUIclosing()
{
myKinect.stop();
}
private void resetKinect()
{
if(turn_off.getText().compareTo("Turn on")==0) return;
myKinect.stop();
int depth_res=Kinect.NUI_IMAGE_RESOLUTION_INVALID;
if(depth_resolution.getSelectedIndex()==0) depth_res=Kinect.NUI_IMAGE_RESOLUTION_80x60;
else if(depth_resolution.getSelectedIndex()==1) depth_res=Kinect.NUI_IMAGE_RESOLUTION_320x240;
else if(depth_resolution.getSelectedIndex()==2) depth_res=Kinect.NUI_IMAGE_RESOLUTION_640x480;
int video_res=Kinect.NUI_IMAGE_RESOLUTION_INVALID;
if(video_resolution.getSelectedIndex()==0) video_res=Kinect.NUI_IMAGE_RESOLUTION_640x480;
else if(video_resolution.getSelectedIndex()==1) video_res=Kinect.NUI_IMAGE_RESOLUTION_1280x960;
myKinect.start(track_skeleton.isSelected(),depth_res,video_res);
myKinect.computeUV(true);
if(seated_skeleton.isSelected())myKinect.startSkeletonTracking(true);
if(near_mode.isSelected()) myKinect.setNearMode(true);
}
public static void main(String args[]) {
createMainFrame("Kinect Viewer App");
app=new KinectViewer();
setFrameSize(730,570,null);
}
@Override
public void GUIactionPerformed(ActionEvent e)
{
if(e.getSource()==near_mode)
{
if(near_mode.isSelected()) myKinect.setNearMode(true);
else myKinect.setNearMode(false);
}
else if(e.getSource()==seated_skeleton)
{
if(seated_skeleton.isSelected()) myKinect.startSkeletonTracking(true);
else myKinect.startSkeletonTracking(false);
}
else if(e.getSource()==track_skeleton)
{
if(track_skeleton.isSelected())
{
if(seated_skeleton.isSelected()) myKinect.startSkeletonTracking(true);
else myKinect.startSkeletonTracking(false);
}
else myKinect.stopSkeletonTracking();
}
else if(e.getSource()==turn_off)
{
if(turn_off.getText().compareTo("Turn off")==0)
{
myKinect.stop();
turn_off.setText("Turn on");
}
else
{
turn_off.setText("Turn off");
resetKinect();
}
}
else if(e.getSource()==depth_resolution)
{
resetKinect();
}
else if(e.getSource()==video_resolution)
{
resetKinect();
}
else if(e.getSource()==show_video)
{
main_panel.setShowVideo(show_video.isSelected());
}
else if(e.getSource()==mask_players)
{
myKinect.maskPlayers(mask_players.isSelected());
}
}
@Override
public void stateChanged(ChangeEvent e) {
if(e.getSource()==elevation_angle)
{
if(!elevation_angle.getValueIsAdjusting())
{
myKinect.setElevationAngle(elevation_angle.getValue());
elevation_angle.setToolTipText("Elevation Angle ("+elevation_angle.getValue()+" degrees)");
}
}
}
}
这是splitpane类(TestSplitPanels.java):
package skeleton;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
public class TestSplitPanels extends JPanel {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final TestSplitPanels tps = new TestSplitPanels();
frame.setContentPane(tps);
frame.pack();
frame.setVisible(true);
}
public TestSplitPanels() {
JTable jt3 = new JTable();
JButton loginbutton = new JButton("Login");
JButton database = new JButton("Database");
// JButton LiveFeed = new JButton("Live Feed");
final JPanel jsr1 = new JPanel();
final JTabbedPane jtp = new JTabbedPane();
jtp.addTab("Floor 1", new Floor1Panel());
jtp.addTab("Floor 2", new Floor2Panel());
jtp.addTab("Floor 3", new Floor3Panel());
add(jtp);
final JScrollPane jsr3 = new JScrollPane();
jsr3.setViewportView(jt3);
ActionListener ButtonHandler = new ButtonHandler();
ActionListener DatabaseHandler = new DatabaseHandler();
jsr1.add(loginbutton);
jsr1.add(database);
loginbutton.addActionListener(ButtonHandler);
database.addActionListener(DatabaseHandler);
jsr1.setVisible(true);
// JPanel feed = new KinectViewer().app;
// jsr3.add(feed);
JSplitPane jsl1 = new JSplitPane();
JSplitPane jsl2 = new JSplitPane();
jsl1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jsl1.setTopComponent(jsr1);
jsl1.setBottomComponent(jsl2);
jsl1.setResizeWeight(0.33); // <-- here
jsl2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jsl2.setTopComponent(jtp);
jsl2.setBottomComponent(jsr3);
jsl2.setResizeWeight(0.5); // <-- here
this.addAncestorListener(new BaseAncestorListener() {
@Override
public void ancestorMoved(AncestorEvent event) {
System.out.println("jsr1 size: " + jsr1.getSize());
System.out.println("jsr2 size: " + jtp.getSize());
System.out.println("jsr3 size: " + jsr3.getSize());
System.out.println("----");
}
});
setLayout(new BorderLayout());
add(jsl1, BorderLayout.CENTER);
}
public static class BaseAncestorListener implements AncestorListener {
@Override
public void ancestorAdded(AncestorEvent event) {
}
@Override
public void ancestorRemoved(AncestorEvent event) {
}
@Override
public void ancestorMoved(AncestorEvent event) {
}
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
}
});
} catch (Exception exc) {
System.out.println("Can't create because of " + exc);
}
}
}
}
如何在KinectViewer的SplitPanes中显示相同的GUI功能?
谢谢!