Formatting in java

Hi, I am writing a java program to output some sort of
receitp for a dental office. I would like for my output to be in
columns. My problem is that my second column is of variable length
which
doesnt let me align subsequent columns neatly thereafter. I even try to
pad short columns with extra white space but it still doesnt work
because white space takes up less than any other character. And using
tab results in the same outcome. What would be a good method to format
text outputs in java? Thank you in advance. Joe

Use Graphics.drawString(String str, int x, int y).
Figure out the length of your longest line in the column to set the x for the next column. (Use FontMetrics to figure out the increments of x and y to use.)

Similar Messages

  • Help needed  while exporting crystal reports to HTML file format using java

    Help needed  while exporting crystal reports to HTML file format using java api(not using crystalviewer).i want to download the
    html file of the report
    thanks

    the ReportExportFormat class does not have HTML format, it has got to be XML. Export to HTML is available from CR Designer only.
    Edited by: Aasavari Bhave on Jan 24, 2012 11:37 AM

  • Converting files into pdf format in java

    Hi all,
    How can we convert a file into PDF format in java?My application does the
    file upload, and I need the files to be converted into PDF format.
    The uploaded file can be of any type. How can I do this?
    Please give me some help.
    Thanks and regards,
    Sandeep.

    >
    How can we convert a file into PDF format in java?My application does the
    file upload, and I need the files to be converted into PDF format.
    The uploaded file can be of any type. ...>1) Write a class that will intelligently render a file of any type..
    2) ... (well, do '1' first, then after getting your Nobel prize for AI, come back and we'll talk)
    >
    Please give me some help.>Please review your requirement.
    BTW
    - PDF sucks. It is designed for printing, and I (for one) don't want to kill more trees, and have no printer.
    - This subject (convert file to PDF) has been discussed on the forums a bazillion times. Did you search the forums before asking your two (very closely related) questions?

  • IS it possible to Format the data to CXML format in Java ?

    Hi all,
    I am new to Java programming. I am an SAP ABAP Developer and in my SAP CRM E-Commerce Web Shop coding, I have to do coding in Java.
    My current requirement is that I have some set of data and I have to format this data to CXML format in Java. IS this possible?
    Can I format the data to CXML format in Java? Are there standard API's to do this? Please let me know how should I procced with the coding?
    Apart from formatting the output to CXML format, I have to also post this data to an external market place...How can I do this?
    Please help me with relevant information. your help will be highly appreciated.
    Regards,
    Jessica Sam

    It should be possible to format the data, yes. If there's a "standard API" it should be one that comes out of that SAP CRM thing, so look there.
    As for "posting to an external marketplace", that's far too vague a concept to be able to answer. You should start by getting the specs about "how to post" from that marketplace.

  • How to store xml data into file in xml format through java program?

    HI Friends,
    Please let me know
    How to store xml data into file in xml format through java program?
    thanks......
    can discuss further at messenger.....
    Avanish Kumar Singh
    Software Engineer,
    Samsung India Development Center,
    Bangalore--560001.
    [email protected]

    Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
    i got a piece of code from the net which allows me to parse th file:
    import java.io.IOException;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    import java.lang.*;
    public class MySaxParser extends DefaultHandler
    private static int INDENT = 4;
    private static String attList = "";
    public static void main(String[] argv)
    if (argv.length != 1)
    System.out.println("Usage: java MySaxParser [URI]");
    System.exit(0);
    String uri = argv[0];
    try
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    MySaxParser MySaxParserInstance = new MySaxParser();
    parser.setContentHandler(MySaxParserInstance);
    parser.parse(uri);
    catch(IOException ioe)
    ioe.printStackTrace();
    catch(SAXException saxe)
    saxe.printStackTrace();
    private int idx = 0;
    public void characters(char[] ch, int start, int length)
    throws SAXException
    String s = new String(ch, start, length);
    if (ch[0] == '\n')
    return;
    System.out.println(getIndent() + " Value: " + s);
    public void endDocument() throws SAXException
    idx -= INDENT;
    public void endElement(String uri, String localName, String qName) throws SAXException
    if (!attList.equals(""))
    System.out.println(getIndent() + " Attributes: " + attList);
    attList = "";
    System.out.println(getIndent() + "end document");
    idx -= INDENT;
    public void startDocument() throws SAXException
    idx += INDENT;
    public void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException
    idx += INDENT;
    System.out.println('\n' + getIndent() + "start element: " + localName);
    if (localName.compareTo("Machine") == 0)
    System.out.println("YES");
    if (attributes.getLength() > 0)
    idx += INDENT;
    for (int i = 0; i < attributes.getLength(); i++)
    attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
    if (i < (attributes.getLength() - 1))
    attList = attList + ", ";
    idx-= INDENT;
    private String getIndent()
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < idx; i++)
    sb.append(" ");
    return sb.toString();
    }// END PRGM
    Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
    The next step is to write the data to the DB.
    Am sending an example of my file:
    <Start>
    <Machine>
    <Hostname> IPCServer </Hostname>
    <HostID> 80c04499 </HostID>
    <MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
    <CPU> UltraSPARC-IIi at 360 MHz </CPU>
    <Memory> RAM : 512 MB </Memory>
    <HostAdapter>
    <HA> kern.info] </HA>
    </HostAdapter>
    <Harddisks>
    <HD>
    <HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
    <HD2> ST38420A 8.2 GB </HD2>
    </HD>
    </Harddisks>
    <GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
    <NetworkType> hme0 : Fast-Ethernet </NetworkType>
    <EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
    <IPAddress> 149.51.23.140 </IPAddress>
    </Machine>
    </Start>
    Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
    Cal u tellme what to do!
    Even better- do u have a piece of code that will help me understand and implement the database writing portion?
    I badly need help here.
    THANX

  • How to SaveAs the MSword file into xml file format using Java APIS?

    Hello all,
    I want to convert MSword file into Xml format using java APIS or any other inbuilt APIS that i can integrate in Java code.

    Sorry, that doesn't make much sense.
    The XML you gave is a configuration file for txt2xml utility. It doesn't represent the output format.
    Are you a user of this utility?

  • STORING DATA IN FILE IN XML FORMAT THROUGH JAVA ?

    HOW TO STORE DATA IN FILE IN XML FORMAT THROUGH JAVA PROGRAM?

    Have you looked into JAXB?
    That is a new way of processing XML into Java classes or visa versa.
    Otherwise, there are a lot of other XML related tools for Java in the -XML link on the left side of the page.

  • How can I convert an image created in Photoshop into a format that Java's ImageIO library will take?

    Hi all,
    I've been trying to write an image resize tool to use the Lancoz resample algorithm to resize images to a high standard in Java.  The library with the algorithm/filter in it is mortennobel's image scaling library and it takes a buffered image as an input and returns the resized image as desired.  However the trouble I’m having is that the ImageIO library in Java, a standard library, which converts images given to its read method to buffered images doesn't accept certain images created in Photoshop and so it throws an exception.  My library needs to be fully automated to process possible thousands of images at a time and so manually converting them by resaving them as JPEG's is really feasibly.  Is there some way I can convert these images from Adobes Exif format to standard JFIF format?  I've tried simple inserting the APP0 marker from a JFIF image in-between the SOI and APP1 marker but the ImageIO library still failed.
    The above image is a screenshot of the binary in hex of one of the images that cause an Invalid Format exception when passed to ImageIO.
    Any help you could offer me with this would be much appreciated.
    Kind regards and thank you,
    Alexei Blue
    Science Warehouse.
    NB: I previously posted this post in Developers but was told to post it in a Photoshop forum so apologies if this is the incorrect formum

    The image scaling library does have a BiCubicFilter in it so I'll experiment around with them and see what happens.  As for the imageIO library I think it accepts Exif image types, but still for some reason it just doesn't like Adobe Photoshop types.  Maybe its the colour map it doesn't like I just can't seem to work out what's wrong which is slightly frustrating but looking round to see if I can find an answer

  • How can i create a printable format with Java

    Hello....
    First, my english is not good, but this is possibly my last hope!! I have a program with EJB's, JBoos and a MySql database! The program shows the data from the database and you can do something with these data. Now my problem to print this data. I want create a formular which will be print! I've treid ut with docbook and the javax.print library.
    The first problem is: with linux docbook works very fine. I transform the sgml-file in many formats with "db2pdf or db2ps......"
    but the javax.print library don't find any printservice! I've J2EE 1.4.1 where the bug canceld from the earlier version!
    So the next problem is: with windows the javax.print library works fine! I find the printservices and can print *.ps or *.pdf! But i can't transform the sgml-file in Postscipt or PDF!
    I've tried to solve this problem for two weeks now, but without any success.
    Now my Question is: have somebody experiences with this problem and can help me or is there another possibility to solve my problem!!!
    Thanks
    FIPS

    seems to be important!
    k, do this.
    1. ur english is wonderful for a programmer, are u US :)
    2. i will suggest u create an XML file.
    then u can print it and do the hell with it.
    so : java ==> XML ==> what ever u want.
    and if u can also what ever u want ==> XML ==> java.
    this works also fine.

  • Converting from milliseconds to a date format in java

    This so that, that date can be inserted into a date column in mysql
    What I have is something like 1119193190
    I do:
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));
    and Java gives me something like:
    Jul 04,2004 14:06
    But Java then when inserting into a mysql table is all like um....no:
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'Jul 04,2004 14:06' for column 'prodDate' at row 1
    proDate is of type date in mysql.
    Help?

    jverd wrote:
    "Jul 04,2004 14:06" is a String, not a Date.
    PreparedStatement ps = conn.prepareStatement("insert into T(name, birthdate) values(?, ?)");
    ps.setString(1, "Joe Smith");
    java.sql.Date date = new java.sql.Date(yourmillis);
    ps.setDate(2, date);
    ps.executeUpdate();
    I am a bit confused
    This i what I have
    for(int i = 0; i < productions.size(); i++)
                        //Create a new Production from the ArrayList
                        Production p = (Production) productions.get(i);
                        //Convert the date from milliseconds to YYYY-MM-DD format. for mysql?
                        SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
                        Date convertedDate = new Date(p.getDate());
                        //Build a query to insert the Production into the table
                        String insertQuery = "INSERT INTO WELL_PROD VALUES(" +
                                  "'" + p.getLocation() + "'," +
                                  "'" + dateFormatter.format(convertedDate) + "'," +
                                  "'" + p.getOilProd() + "'," +
                                  "'" + p.getWaterProd() + "'," +
                                  "'" + p.getGasProd() + "')";
                        //Print the query to the screen
                        System.out.println("-> INSERTING the following query into well_prod: ");
                        System.out.println("   " + insertQuery);
                        //Update the database using the constructed query
                        int result = statement.executeUpdate(insertQuery);
                        //Print out the result of the insertion
                        System.out.println("   INSERT RESULT: " + result);
                   }Are you saying something like
    java.sql.Date date = new java.sql.Date(Something , what I have no idea, Should go here);
    instead of
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    and then carry on as normal?
    If so, what should go in those brackets based on the code?
    java.sql.Date date = new java.sql.Date("MMM dd,yyyy HH:mm");
    This is all being read in from a text file and converted over before being spit out to the data base, it all works except for the date...

  • How to export report IN CSV format through JAVA.

    how to export report in csv format.when try to export in csv format.its exporting into csv but report not containing column heading , report heading and it showing all the data in a single line.we have integrated the reports with java.

    Use a Java API which can create PDF files based on some collection of plain vanilla Java objects (List, String, Number, etc).
    Google can find them all. Just feed it with something like "Java PDF API" or so. A commonly used one is iText.
    That said, when talking about this in JSP context, ensure that you do NOT write raw Java code in JSP files using scriptlets. Raw Java code belongs in Java classes. In such case you need a Servlet. In JSP just use taglibs and EL to interact with backend Java code and data. Scriptlets are discouraged since over a decade.

  • How to convert a file format thru java

    Hello friends
    I would like to know how to convert a file format i.e. from x to y ie using java meaning x file comes it will be converted by an exe to y format.
    how can this be achieved in java
    heko

    Open file x with a FileReader or BufferedReader or maybe another class. Search Java API for this.
    Read file x.
    Converts contents as you want.
    Write file y by a FileWriter or BufferedWriter.
    Regards,
    Hartmut

  • Date formatting with java and axis

    Hi,
    My wsdl file has date field which uses xsd:dateTime data type. In my web service implementation java class I am passing value to this variable using Calendar.getInstance().
    I am using Axis framework. When I check my soap output using TCP monitor I find that the date is of format eg: 2007-01-02T12:01:23.342Z.
    The date output belongs to GMT and includes character Z. How do I get SOAP output in locale specific date time format. I used xsd:dateTime along with format parameter but no use.
    Regards,
    Shankar

    The date is wrong because I ran the test using october
    20th data and my data showed up.
    The actual test is from 9/1 to 10/19.This still doesn't tell me what you tried, what you expected, or what you got. If you use the timestamps that you mentioned in your earlier post:
    from: Wed Sep 01 00:00:00 CDT 2004
    to: Wed Oct 20 00:00:00 CDT 2004
    then you will get all timestamps from Sept 01 to Oct 19, inclusive. You won't get any on October 20 except for 00:00:00. Was that what you expected or was it not?
    I'm still guessing here, but possibly the timestamps in your database aren't in the same timezone as CDT. If they are GMT timestamps then you'll be off by, what is it, three or five hours?

  • Question with SIMPLEDATE FORMAT in Java

    How can I convert my Date field in the the format I want with Simple Date format.
    Calendar cal1 = Calendar.getInstance(TimeZone.getDefault());
                   String DATE_FORMAT = "yyyy-MM-dd"; //
                   java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
                   sdf.setTimeZone(TimeZone.getDefault());
                   String now = sdf.format(cal1.getTime());This code gives me the format I want, if I use a String , but I want to have this format in my DATE filed called START_DATE.
    How can I do that?I am sorry, I am learning Java, so this might be very idiotic questions to ask..but if anybody can help me??
    Thanks,
    Edited by: ASH_2007 on Mar 18, 2008 10:30 AM

    Yes, I know how to do that for a String.
    But how do I do the same thing for Date fields?I believe I already mentioned that is non-sensical in java. There is no such thing as a "date field".
    There is a Date object. And you use SimpleDateFormat to display it.
    There are datatypes in a database that are associated with timestamp values. And I already explained to you that, as you have already found out, that datatype holds a timestamp. It does not hold a date (just a date) and it never will. It is not possible.
    In terms of displaying (not storing) something in the database itself, not java, the way that you do that depends on the database.
    But regardless of the database you MUST still do something in terms of DISPLAYING it to make a timestamp appear as display value that looks like a date.
    Now exactly which parts of the above do you not understand????
    Stop telling us what you want to do and start asking questions about what we said - because it is obvious that you are having problems with concepts, not code. And until you understand the comments you can't phrase a question correctly so that one can answer it with code.

  • Function: Export Data in Excel Format generate Java errors

    java.lang.NumberFormatException
         at java.math.BigDecimal.<init>(BigDecimal.java:368)
         at java.math.BigDecimal.<init>(BigDecimal.java:647)
         at oracle.dbtools.raptor.format.ExcelFormatter.printColumn(ExcelFormatter.java:170)
         at oracle.dbtools.raptor.format.ui.TableFormatterWrapper.print(TableFormatterWrapper.java:114)
         at oracle.dbtools.raptor.format.ResultsFormatter.print(ResultsFormatter.java:173)
         at oracle.dbtools.raptor.format.ResultsFormatter$1.doWork(ResultsFormatter.java:133)
         at oracle.ide.dialogs.ProgressRunnable.run(ProgressRunnable.java:161)
         at oracle.ide.dialogs.ProgressBar.run(ProgressBar.java:615)
         at java.lang.Thread.run(Thread.java:595)

    Already reported, bugged and fixed (presumably in EA2), as per:
    EA1 - Error with exporting output to xls

Maybe you are looking for