0
當我運行該程序時,JPanel不可見。儘管它沒有JScrollPane。這真讓我抓狂!之前,我使用了Canvas和ScrollPane。請注意,FlowchartPanel擴展了JPanel。Java swing JPanel和JScrollPane不顯示
public class Window extends JFrame{
private FlowchartPanel panel; // contains all the main graphics
private JScrollPane scrollpane; // contains panel
private int canvasWidth, canvasHeight; // the width and height of the canvas object in pixels
private Flowchart flowchart; // the flowchart object
public Window(Flowchart flowchart) {
super();
canvasWidth = 900;
canvasHeight = 700;
this.flowchart = flowchart;
flowchart.setWidth(canvasWidth);
flowchart.setHeight(canvasHeight);
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel = new FlowchartPanel(flowchart);
panel.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
scrollpane = new JScrollPane();
scrollpane.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
scrollpane.add(panel);
add(scrollpane);
//add(panel);
pack();
}
}
謝謝!這解決了它! –