JScrollPane الآن تظهر المعاينة
-
19-08-2019 - |
سؤال
وأنا على صنع تطبيق جافا سوينغ لدي مشكلة.لقد جعلت من كلفه الفريق التي تحتاج إلى عقد لوحة بسيطة ، و انتقل الفريق.بسيطة الفريق يعمل بشكل جيد ولكن في التمرير لوحة أستطيع أن أرى فقط التمرير ، ولكن ليس على المعاينة ، قانون بلدي على النحو التالي:
ContentPane
public class ContentPane extends JTabbedPane {
private InfoPanel ip;
ScrollPanel sp;
public InfoPanel getIp() {
return ip;
}
public ContentPane(GraphPanel gp) {
this.sp = new ScrollPanel(gp);
this.sp.setViewportView(gp);
this.addTab("Graph", this.sp);
this.ip = new InfoPanel(gp);
this.addTab("Info", ip);
}
}
ScrollPanel
public class ScrollPanel extends JScrollPane {
public ScrollPanel(GraphPanel gp){
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.repaint();
}
}
GraphPanel
public GraphPanel(StatusBar sb) {
this.sb = sb;
zoomLevel = 5;
sm = new Simulation();
mh = new MouseHandler(this, sm);
this.addMouseListener(mh);
this.setBackground(new Color(240, 165, 98));
this.repaint();
}
منذ أن كنت لا تحصل على أي أخطاء أو استثناءات ، أنا الآن فقدت تماما في aproach أن تأخذ.
المحلول
يجب أن لا فرعية JScrollPane ، فإنه ليس من الضروري.
ولكن إذا كنت تفعل ذلك, لا تنسى أن إضافة عنصر إلى scrollpane.
في فرعية أنت لا إضافة GraphPanel إلى انتقل جزء.:
public class ScrollPanel extends JScrollPane {
public ScrollPanel(GraphPanel gp){
// :::: HERE ::: you are not doing anything with gp
// like this.setViewPort( gp ) or something like that
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.repaint();
}
}
محاولة:
public class ScrollPanel extends JScrollPane {
public ScrollPanel(GraphPanel gp){
super( gp );
.... etc ...
و قد GraphPanel تمديد JComponent أو JPanel
لا تنتمي إلى StackOverflow