File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How do i print in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do i print in java" Watch "How do i print in java" New topic

How do i print in java

Jimmy Thakkar

Joined: Oct 03, 2001
Posts: 2
How do i print in java
how do i print contents of listbox!
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

To print to the console ( i.e. the OS window the java program is running in... ) use

Is the class you are trying to print the contents of a List ( in java.awt ) or a JList ( in javax.swing )?


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
shweta agarwal

Joined: Aug 30, 2001
Posts: 10
to print anything use:
System.out.println("string1" + "string2" + variables);
u can thus overload + operator to get the expression of ur desire by making any combination.
u can also use System.out.print (instead of System.out.println) if u dont want to switch over to the next line after printing the stuff in the first line.
to print the contents of a listbox use the following 2 methods:
int countItem()
this returns the total number of items in the list.
and once u have the total number of items in the list u can use the following method in a loop
String getItem(int)
which returns the item at int position.
so ur code would be something like this(if ur list is l1)
int i = l1.countItem();
for(int j=0;j<i;j++)>

shweta agarwal
Sun Certified Programmer for the Java� 2 Platform

I agree. Here's the link:
subject: How do i print in java
It's not a secret anymore!