Java 两个并排的框架

Java 两个并排的框架,java,swing,jframe,awt,Java,Swing,Jframe,Awt,是否可以设置两个不同的JFrame并并排显示?在不使用Internalframe的情况下,多个JPanel等将帧首先放置在每个屏幕设备上 frame1.setLocation(pointOnFirstScreen); frame2.setLocation(pointOnSecondScreen); 工作示例: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Frame; import java.awt.G

是否可以设置两个不同的JFrame并并排显示?在不使用Internalframe的情况下,多个JPanel等将帧首先放置在每个屏幕设备上

frame1.setLocation(pointOnFirstScreen);
frame2.setLocation(pointOnSecondScreen);
工作示例:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class GuiApp1 {
protected void twoscreen() {
Point p1 = null;
Point p2 = null;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment ().getScreenDevices()) {
    if (p1 == null) {
        p1 = gd.getDefaultConfiguration().getBounds().getLocation();
    } else if (p2 == null) {
        p2 = gd.getDefaultConfiguration().getBounds().getLocation();
    }
}
if (p2 == null) {
    p2 = p1;
}
createFrameAtLocation(p1);
createFrameAtLocation(p2);
 }

 private void createFrameAtLocation(Point p) {
final JFrame frame = new JFrame();
frame.setTitle("Test frame on two screens");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new BorderLayout());
final JTextArea textareaA = new JTextArea(24, 80);
textareaA.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
panel.add(textareaA, BorderLayout.CENTER);
frame.setLocation(p);
frame.add(panel);
frame.pack();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible(true);
 }

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {


    public void run() {
        new GuiApp1().twoscreen();
    }
});
  }

}
是的,具体如下

JFrame leftFrame = new JFrame();

// get the top left point of the left frame
Point leftFrameLocation = leftFrame.getLocation();
// then make a new point with the same top (y) and add the width of the frame (x)
Point rightFrameLocation = new Point(
            leftFrameLocation.x + leftFrame.getWidth(),
            leftFrameLocation.y);

JFrame rightFrame = new JFrame();
rightFrame.setLocation(rightFrameLocation); // and that's the new location

看看JFrame-method,它与设置框架的大小相结合,可以并排放置两个应用程序窗口,只是为了澄清:你是指并排放置两个应用程序窗口,还是一个应用程序窗口中并排放置两个部分?并非所有可能的方法都是明智的。看起来你想要一个JFrame,两个JPanel并排。@makciook是的,可以按你说的做。但是还有另一个可能性吗?我真的会考虑GilbertLeBlanc的建议,尤其是考虑到答案。