पर एक ड्राइंग नहीं है जो मेरे पास एक कस्टम घटक है जो जेकंपोनेंट को बढ़ाता है, जो विधि पेंट कॉम्पोनेंट (ग्राफिक्स जी) को ओवरराइड करता है लेकिन जब मैं इसे अपने जेपीनल में जोड़ने की कोशिश करता हूं तो यह काम नहीं करता है, कुछ भी नहीं खींचा जाता है। - JPanel घटक में जोड़ा जा रहा है, लेकिन यह कितना बड़ा हैजेकंपोनेंट जेननेल
public class SimpleComponent extends JComponent{
int x, y, width, height;
public SimpleComponent(int x, int y, int width, int height){
this.x = x;
this.y = y;
}
@Override
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
g2.fillRect(x, y, width, height);
}
}
public class TestFrame{
public static void main(String[] args){
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setPreferredSize(new Dimension(400, 400));
frame.add(panel);
frame.pack();
frame.setResizable(false);
SimpleComponent comp = new SimpleComponent(10, 10, 100, 100);
panel.add(comp);
frame.setVisible(true);
}
}
यह वास्तव में अजीब है, विंडोज और मैक पर इस समस्या को दोहराया ive और चौड़ाई और ऊंचाई यह अभी भी काम नहीं किया भागों को स्थापित करने के लिए याद करने के बाद इसकी हमेशा ठीक उसी – lilroo
आह, चौड़ाई और ऊंचाई शून्य – lilroo
के लिए निर्धारित है, लेकिन जब मैंने विधि को ओवरराइड किया था तो प्रीपेरड साइज() यह काम करता था। – lilroo