Foros del Web » Programación para mayores de 30 ;) » Java »

panel y GridBagLayout

Estas en el tema de panel y GridBagLayout en el foro de Java en Foros del Web. tengo el siguiente codigo; @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Java: Ver original public class Ventana extends JPanel //con JFrame visualiza lo que necesito realizar   {   ...
  #1 (permalink)  
Antiguo 02/02/2011, 11:28
Avatar de valdo_kof  
Fecha de Ingreso: noviembre-2009
Ubicación: San Juan del Rio, Qro
Mensajes: 192
Antigüedad: 14 años, 5 meses
Puntos: 16
Pregunta panel y GridBagLayout

tengo el siguiente codigo;

Código Java:
Ver original
  1. public class Ventana extends JPanel //con JFrame visualiza lo que necesito realizar
  2.  {    
  3.      public Ventana() throws BarcodeException, FileNotFoundException, OutputException, IOException
  4.      {
  5.         super ();
  6.          this.setLayout(new GridBagLayout());
  7.          this.setSize(470, 350);
  8.           this.setBackground(Color.white);
  9.          GridBagConstraints constraints = new GridBagConstraints();
  10.        Barcode barcode = BarcodeFactory.createCode39("N14U-93110-00",false);
  11. barcode.setDrawingText(false);
  12.  barcode.setBarHeight(50);
  13.  barcode.setBarWidth(2);
  14.  FileOutputStream fos = new FileOutputStream("c:/N14U-93110-00.jpeg");
  15.   BarcodeImageHandler.writeJPEG(barcode, fos);
  16.    ImageIcon icon = new ImageIcon("c:/N14U-93110-00.jpeg");
  17. Barcode barcode_q = BarcodeFactory.createCode39("Q8",false);
  18. barcode_q.setDrawingText(false);
  19.  barcode_q.setBarHeight(50);
  20.  barcode_q.setBarWidth(2);
  21.  FileOutputStream fos_q = new FileOutputStream("c:/q8.jpeg");
  22.   BarcodeImageHandler.writeJPEG(barcode_q, fos_q);
  23.    ImageIcon icon_q = new ImageIcon("c:/q8.jpeg");
  24.    Barcode barcode_l = BarcodeFactory.createCode39("L1111",false);
  25. barcode_l.setDrawingText(false);
  26.  barcode_l.setBarHeight(50);
  27.  barcode_l.setBarWidth(2);
  28.  FileOutputStream fos_l= new FileOutputStream("c:/l1111.jpeg");
  29.  BarcodeImageHandler.writeJPEG(barcode_l, fos_l);
  30.  ImageIcon icon_l = new ImageIcon("c:/l1111.jpeg");
  31.  JLabel country=new JLabel("HARADA INDUSTRY OF AMERICA");
  32.  country.setFont(new java.awt.Font("Arial", 1, 14));
  33.  JLabel item=new JLabel("ITEM No.");
  34.  item.setFont(new java.awt.Font("Arial", 1, 8));
  35.  JLabel item_comp=new JLabel("(N)");
  36.  item_comp.setFont(new java.awt.Font("Arial", 1, 8));
  37.  JLabel item_no=new JLabel("14U-93110-00");
  38.  item_no.setFont(new java.awt.Font("Arial", 1, 20));
  39.  JLabel image=new JLabel();
  40.  image.setIcon(icon);
  41.  JLabel espacio=new JLabel(" ");
  42.  JLabel qty=new JLabel("8");
  43.  qty.setFont(new java.awt.Font("Arial", 1, 20));
  44.  JLabel Quantity=new JLabel("Quantity");
  45.  Quantity.setFont(new java.awt.Font("Arial", 1, 8));
  46.  JLabel q=new JLabel("(Q)");
  47.  q.setFont(new java.awt.Font("Arial", 1, 8));
  48.  JLabel image_q=new JLabel();
  49.  image_q.setIcon(icon_q);
  50.  JLabel l=new JLabel("1111");
  51.  l.setFont(new java.awt.Font("Arial", 1, 20));
  52.  JLabel lot=new JLabel("Lot No.");
  53.  lot.setFont(new java.awt.Font("Arial", 1, 8));
  54.  JLabel lo=new JLabel("(L)");
  55.  lo.setFont(new java.awt.Font("Arial", 1, 8));
  56.  JLabel image_l=new JLabel();
  57.  image_l.setIcon(icon_l);
  58.  JLabel c=new JLabel("28200 9E000");
  59.  c.setFont(new java.awt.Font("Arial", 1, 20));
  60.  JLabel cus=new JLabel("Customer No.");
  61.  cus.setFont(new java.awt.Font("Arial", 1, 8));
  62.  JLabel country2=new JLabel("ASSEMBLED IN MEXICO.");
  63.  country2.setFont(new java.awt.Font("Arial", 1, 14));
  64.          constraints.gridx = 1;
  65.          constraints.gridy = 0;
  66.          constraints.gridwidth = 1;
  67.          constraints.gridheight = 1;
  68.         constraints.weightx=0;
  69.         constraints.weightx=0;
  70.          this.add (country, constraints);
  71.          constraints.gridx = 0;
  72.          constraints.gridy = 1;
  73.          constraints.gridwidth = 1;
  74.          constraints.gridheight = 1;
  75.          this.add (item, constraints);
  76.          constraints.gridx = 0;
  77.          constraints.gridy = 2;
  78.          constraints.gridwidth = 1;
  79.          constraints.gridheight = 1;
  80.          this.add (item_comp, constraints);
  81.          constraints.gridx = 1;
  82.          constraints.gridy = 2;
  83.          constraints.gridwidth = 1;
  84.          constraints.gridheight = 1;
  85.          this.add (item_no, constraints);
  86.      constraints.gridx = 1;
  87.          constraints.gridy = 3;
  88.          constraints.gridwidth = 1;
  89.          constraints.gridheight = 1;
  90.          this.add (image, constraints);
  91.          constraints.gridx = 0;
  92.          constraints.gridy = 4;
  93.          constraints.gridwidth = 1;
  94.          constraints.gridheight = 1;
  95.          this.add (espacio, constraints);
  96.          constraints.gridx = 0;
  97.          constraints.gridy = 5;
  98.          constraints.gridwidth = 1;
  99.          constraints.gridheight = 1;
  100.          this.add (Quantity, constraints);
  101.          constraints.gridx = 0;
  102.          constraints.gridy = 6;
  103.          constraints.gridwidth = 1;
  104.          constraints.gridheight = 1;
  105.          this.add (q, constraints);
  106.          constraints.gridx = 1;
  107.          constraints.gridy = 6;
  108.          constraints.gridwidth = 1;
  109.          constraints.gridheight = 1;
  110.          this.add (qty, constraints);
  111.          constraints.gridx = 1;
  112.          constraints.gridy = 7;
  113.          constraints.gridwidth = 1;
  114.          constraints.gridheight = 1;
  115.          this.add (image_q, constraints);
  116.          constraints.gridx = 0;
  117.          constraints.gridy = 8;
  118.          constraints.gridwidth = 1;
  119.          constraints.gridheight = 1;
  120.          this.add (espacio, constraints);
  121.          constraints.gridx = 0;
  122.          constraints.gridy = 9;
  123.          constraints.gridwidth = 1;
  124.          constraints.gridheight = 1;
  125.          this.add (lot, constraints);
  126.          constraints.gridx = 0;
  127.          constraints.gridy = 10;
  128.          constraints.gridwidth = 1;
  129.          constraints.gridheight = 1;
  130.          this.add (lo, constraints);
  131.          constraints.gridx = 1;
  132.          constraints.gridy = 10;
  133.          constraints.gridwidth = 1;
  134.          constraints.gridheight = 1;
  135.          this.add (l, constraints);
  136.          constraints.gridx = 1;
  137.          constraints.gridy = 11;
  138.          constraints.gridwidth = 1;
  139.          constraints.gridheight = 1;
  140.          this.add (image_l, constraints);
  141.          constraints.gridx = 0;
  142.          constraints.gridy = 12;
  143.          constraints.gridwidth = 1;
  144.          constraints.gridheight = 1;
  145.          this.add (espacio, constraints);
  146.          constraints.gridx = 0;
  147.          constraints.gridy = 13;
  148.          constraints.gridwidth = 1;
  149.          constraints.gridheight = 1;
  150.          this.add (cus, constraints);
  151.          constraints.gridx = 1;
  152.          constraints.gridy = 13;
  153.          constraints.gridwidth = 1;
  154.          constraints.gridheight = 1;
  155.          this.add (c, constraints);
  156.          constraints.gridx = 1;
  157.          constraints.gridy = 14;
  158.          constraints.gridwidth = 1;
  159.          constraints.gridheight = 1;
  160.          this.add (country2, constraints);
  161.           BufferedImage imagen = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
  162.          Graphics g = imagen.getGraphics();
  163.         this.paint(g);
  164.        ImageIO.write(imagen,"jpg",new File("c:/prueba.jpg"));
  165.      }
  166.      public static void main(String args[]) throws BarcodeException, FileNotFoundException, OutputException, IOException{
  167.      Ventana obj= new Ventana();
  168.      obj.setVisible(true);
  169.      }
  170. }


lo ocupo para poder hacer el diseño de una etiqueta y guardarla en una imagen jpg

el codigo me crea la imagen pero solo me pone el panel en blanco sin ningun componente agregado en las lineas this.add (componente, constraints);

no se que estoy haciendo mal

si cambio public class Ventana extends JPanel por
public class Ventana extends JFrame

se puede ver el diseño de como necesito que quede mi imagen, bueno y tambien necesito encerrar cada segento en un rectangulo

con este codigo me crea los rectangulos q necesito y el tamaño adecuado en la cual debe de quedar mi imagen solo falta hacer q aparescan los componentes q se agregan con this.add (componente, constraints);

solo le agregue al codigo de arriba este pedacito



Código Java:
Ver original
  1. public class Ventana extends JFrame
  2.  {
  3.    
  4.      public Ventana() throws BarcodeException, FileNotFoundException, OutputException, IOException
  5.      {
  6.         super ();
  7.          this.setLayout(new GridBagLayout());
  8.          this.setSize(300, 295);
  9. .
  10. .
  11. .
  12.          g.drawRect(1, 1, 296, 108);
  13.          g.drawRect(1,109, 296, 72);
  14.           g.drawRect(1,181, 296, 72);
  15.           g.drawRect(1,253, 296, 38);
  16.           g.setXORMode(Color.black);  
  17.           this.paint(g);
  18.           ImageIO.write(imagen,"jpg",new File("c:/prueba.jpg"));
  19.      }
  20.      public static void main(String args[]) throws BarcodeException, FileNotFoundException, OutputException, IOException{
  21.      Ventana obj= new Ventana();
  22.      obj.setVisible(true);
  23.      }
  24. }

si alguien puede ayudarme se los agradecere infinitamente

Última edición por valdo_kof; 02/02/2011 a las 13:00
  #2 (permalink)  
Antiguo 12/04/2011, 10:03
Avatar de valdo_kof  
Fecha de Ingreso: noviembre-2009
Ubicación: San Juan del Rio, Qro
Mensajes: 192
Antigüedad: 14 años, 5 meses
Puntos: 16
Respuesta: panel y GridBagLayout

solucionado, gracias por leer mi problema

Etiquetas: panel
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:49.