프로젝트 작업을하고 있습니다. 프로젝트의 한 부분에서 JPanel을 그릴 필요가있었습니다. Graphics2D 객체는 프레임 워크의 모델 부분에 전달되고 모델은 해당 인스턴스에서 그릴 필요가있는 모든 것을 그립니다. 문제는 JFrame이 올바르게 렌더링되지 않습니다. 음영이 절반 흰색이며 올바르게 페인팅되지 않습니다. 내 노트북 (Sony Vaio, Windows7)에서는 정상적으로 작동하지만 테스트 한 다른 모든 시스템 (2 Dell 랩톱, windows8; 1 Thoshiba, windows7, 1 samsung, windows8)에서는 올바르게 렌더링되지 않습니다. 팀 동료가 테스트 한 몇 가지 다른 시스템에서도 올바르게 렌더링됩니다.Java Swing이 올바르게 렌더링되지 않습니다.
모델 부품에 오류가 없습니다. JPanel에서 문제가 렌더링되지 않는 것 같습니다. 하지만 내가 할 수있는 한 가지 정보는 Netbeans에서 우리 프로젝트를하고 있다는 것입니다. 아마도 Netbeans IDE에서 문제를 일으키는 코드가 생성 되었습니까? 코드를 확인했지만 문제를 확인할 수 없습니다. SSCCE를 게시하기는 어렵지만 문제의 스크린 샷을 몇 가지 공유 할 것입니다. 나는 이미지 아래의 링크를 참조 게시 할 수있는 충분한 명성을하지 않기 때문에 좋아
는 ....
[Displays Wrongly][1]
[Displays Wrongly][2]
[Displays correctly on my system][3]
[Displays Correctly on my system][4]
나는 .... 를 디버깅하는 시도했지만 문제가 무엇인지 알 수 없다 그것은이 SSCCE은 아니지만이 JFrame의를 위해
코드를 도움이 될 수 업데이트 ....
<pre>
import btapp.Question;
import btapp.qGens.QGenGeomAbstract;
import btapp.qGens.QGenI;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JPanel;
public class UItestGeomFrame extends javax.swing.JFrame implements UIFrameI, UIGeomFrameAbstract {
/**
* Creates new form UItestGeomFrame
*/
public UItestGeomFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
unitTestGeomPanel1 = new btapp.ui.UnitTestGeomPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Draw Panel JUnitTestCase");
unitTestGeomPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout unitTestGeomPanel1Layout = new javax.swing.GroupLayout(unitTestGeomPanel1);
unitTestGeomPanel1.setLayout(unitTestGeomPanel1Layout);
unitTestGeomPanel1Layout.setHorizontalGroup(
unitTestGeomPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 406, Short.MAX_VALUE)
);
unitTestGeomPanel1Layout.setVerticalGroup(
unitTestGeomPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 260, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(160, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(142, 142, 142))
.addGroup(layout.createSequentialGroup()
.addGap(76, 76, 76)
.addComponent(unitTestGeomPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(30, 30, 30)
.addComponent(unitTestGeomPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(UItestGeomFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(UItestGeomFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(UItestGeomFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(UItestGeomFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UItestGeomFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private btapp.ui.UnitTestGeomPanel unitTestGeomPanel1;
// End of variables declaration
@Override
public void presentQuestions(Question qO, int qNo) {
ArrayList qd = qO.getQuestionDraw();
unitTestGeomPanel1.setQObject(qd);
unitTestGeomPanel1.repaint();
}
@Override
public void presentAnswers(Question qO, int qNo) {
ArrayList ad = qO.getAnswerDraw();
unitTestGeomPanel1.setQObject(ad);
unitTestGeomPanel1.repaint();
}
@Override
public void presentQuestions(Question qO, int qNo, QGenI qg) {
unitTestGeomPanel1.setqGen(qg, qO, 0);
unitTestGeomPanel1.repaint();
}
@Override
public void presentAnswers(Question qO, int qNo, QGenI qg) {
unitTestGeomPanel1.setqGen(qg, qO, 1);
unitTestGeomPanel1.repaint();
}
@Override
public int getHeight(){
return unitTestGeomPanel1.getHeight();
}
@Override
public int getWidth(){
return unitTestGeomPanel1.getWidth();
}
}
</pre>
공동 드 JPanel의
에 대한import btapp.Question; import btapp.qGens.QGenGeomAbstract; import btapp.qGens.QGenI; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Shape; import static java.awt.image.ImageObserver.HEIGHT; import static java.awt.image.ImageObserver.WIDTH; import java.util.ArrayList; public class UnitTestGeomPanel extends javax.swing.JPanel { private int type; /** * Creates new form UnitTestGeomPanel */ public UnitTestGeomPanel() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); }// // Variables declaration - do not modify // End of variables declaration ArrayList dAL = new ArrayList(); private double h, w; @Override public void paintComponent(Graphics g) { super.paintComponent(g); System.out.println("repainign based on QO object of type "+type); if(type == 0){ qg.presentQuestions(qO, (Graphics2D)g); } else if(type == 1) qg.presentAnswers(qO, (Graphics2D)g); } void setQObject(ArrayList dAL) { this.dAL = dAL; } QGenI qg; Question qO; void setqGen(QGenI qg, Question qO, int type) { this.qO = qO; this.qg = qg; this.type = type; } }
은 ... 제발 도와주세요
이편집 사전에 감사 : 일 이후 문제가 더 악화로도 아니지만 내 시스템에서 발생합니다. 댓글의 이미지를 참조하십시오.
링크 [1] : http://i.stack.imgur.com/9xIri.png [2] : HTTP : //i.stack.imgur. com/ll3g0.png [3] : http://i.stack.imgur.com/sOTYL.png [4] : http://i.stack.imgur.com/1Ao5r.png – pinkpanther
편집 중단 당신을 도우려는 사람들의 질문 아래의 '수정'링크를 사용하여 수정하십시오. –
빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –