(new myPanel()) .getGraphicsConfiguration() dlaczego null?

0
class myPanel extends JPanel
{
    public void MyPanel() 
    {
    repaint();
    } 
      public void paintComponent(Graphics g) 
      {
      super.paintComponent(g);
//      System.out.println("paintComponent...");
      dm=jInternalFrame1.getSize();
      if(flaga_slider==true){
//      System.out.println("flaga_slider=true");
   //   toBufferedImage(dst);
  //    g=bimage.createGraphics();
      g.drawImage(dst, 0, 0, dm.width,dm.height , this);
      g.dispose();
      }else{
 //     System.out.println("flaga_slider=false");    
      g.drawImage(image, 0, 0, dm.width,dm.height , this);
      }
      }
    
} 

(new myPanel()).getGraphicsConfiguration()
Co trzeba ustawić żeby (new myPanel()).getGraphicsConfiguration() nie było zerem?

0

Gets the GraphicsConfiguration associated with this Component. If the Component has not been assigned a specific GraphicsConfiguration, the GraphicsConfiguration of the Component object's top-level container is returned. If the Component has been created, but not yet added to a Container, this method returns null.

Kawalek dokumentacji zapoznaj sie z nia.

0

czyli jak zapisać to dodanie do kontenera bo wtedy nie powinno być null tak?

0

Tak.

0

ale jak to zapisać bo nie wiem jak add(component); czy component.add(component)? czy jeszcze jakoś inaczej?

0

myPanel p = new myPanel();
this.getContentPane().add(p);
p.getGraphicsConfiguration();

Tak na przyklad

0

1.Nie sprawdzałem, piszę na wyczucie

    MyPanel mp=new MyPanel();
    container.add(mp);
    mp.getGraphicsConfiguration();
    public void MyPanel() // to ma być konstruktor ?, jeśli tak, to nie jest
                                    // zresztą wywołanie repaint() w konstruktorze jest bez sensu,
                                    // jeśli nie, to nazwa metody jest wyjątkowo nierozsądnie wybrana 
    {
        repaint();
    } 
0

ale co to jest ten container?

0

A skąd ja mam to wiedzieć ?
Jak chcesz żeby ten twój MyPanel było widać, to go gdzieś umieszczasz. container to jest właśnie to (może inny JPanel, może JFrame).

0

dalej jest null
System.out.println(mp.getGraphicsConfiguration());

0

A pokaz wiecej kodu - w ktory momencie dodajesz panel do kontenera itp itd.

0
 private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    alert();
    if(flaga_button==true){
            try {
            //    System.out.print("test");
          
          //     BufferedImage input = toBufferedImage(dst);
              //  File file=new File();
             //   BufferedImage bimage = ImageIO.read(file);
                filtr_alpha();
                
                GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();   
                //int transparency = Transparency.TRANSLUCENT;
                GraphicsDevice gs = ge.getDefaultScreenDevice();
              /*  GraphicsConfigTemplate gct=new GraphicsConfigTemplate() {

                    @Override
                    public GraphicsConfiguration getBestConfiguration(GraphicsConfiguration[] gc) {
                    
                    }

                    @Override
                    public boolean isGraphicsConfigSupported(GraphicsConfiguration gc) {
                    gc.
                        throw new UnsupportedOperationException("Not supported yet.");
                    }
                };*/
                GraphicsConfiguration gc = (new myPanel()).getGraphicsConfiguration();
              //  panel=new myPanel();
            jInternalFrame1.addNotify();
            (new myPanel()).addNotify();
                ImageCapabilities ic=dst.getCapabilities(gc);
//           jInternalFrame1.add(gc);
           new myPanel().add(new myPanel());
           panel=new myPanel();
           panel.addNotify();
           myPanel mp=new myPanel();
          
    con.add(mp);
    System.out.println(mp.getGraphicsConfiguration());
    //      ((new myPanel()).getGraphicsConfiguration());
              //  gc.createCompatibleVolatileImage(dst.getWidth(null), dst.getHeight(null), ic)
    BufferedImage input = (mp.getGraphicsConfiguration()).createCompatibleImage(500, 500,BufferedImage.TYPE_INT_RGB);
    //   System.out.println("dwadwa"+input.toString());
                System.out.println(dst);
            Graphics bg = input.getGraphics(); //ustawic na dst wrazie czego
            bg.drawImage(dst, 0, 0, null);
            bg.dispose();

           
          //    BufferedImage input =convert(graf);
      //   System.out.println(file.getPath().toString());
              // Create the buffered image
                //(BufferedImage) dst;
       //         JAI.create("filestore", dst, "image.jpg", "JPEG");
        //      File inputFile = new File(dst.getGraphics().);
       //       BufferedImage input = ImageIO.read(inputFile);
                File outputFile = file;
                if (outputFile == null) {
                    System.err.println("prosze wybrać obrazek");
                } else {
                    ImageIO.write(input, "JPG", outputFile);                                          
                }
            } catch (IOException ex) {
                Logger.getLogger(ImageViewView.class.getName()).log(Level.SEVERE, null, ex);
            }
        
    }
    }

pomoże ktoś?

1 użytkowników online, w tym zalogowanych: 0, gości: 1