Jayashri
Jayashri

Reputation: 366

Barcode generation in java

I am making an application to generate barcodes, but it does not give me the barcode: the application returns the text that I have provided. My code is:

Code39 code39=new Code39();
String outputStr=code39.encode("12345678", 1);
String humanTextStr=code39.getHumanText();
jLabel1.setText(outputStr);
jLabel1.setFont(new java.awt.Font("CCode39_S3",java.awt.Font.PLAIN,24));

Please can anyone tell me why this happens?

Upvotes: 5

Views: 6845

Answers (2)

Nitesh Verma
Nitesh Verma

Reputation: 1815

Your application is returning a text because you have told it to get the text not the bar-code.

Try the following code:

a=jTextField24.getText();      
Code39 barcode=new Code39();      
barcode.setData(a);      
ImageIcon icon = new ImageIcon(barcode.drawBarcode());          
jLabel34.setIcon(icon);

Upvotes: 6

krishnakumarp
krishnakumarp

Reputation: 9295

Try using open source libraries for generating barcodes in java. For e.g., iText or http://barbecue.sourceforge.net/

Please refer to this link as well BarCode Image Generator in Java

Hope it helps.

Upvotes: 2

Related Questions