Printing table with lines in Java - java

I have some string data that needs to be printed inside a table in java.
Simply formatting the text is not enough, I need to actually draw the lines of the table, have a title, header, and footer.
From my searches I found that java.swing.JTable would fulfill my conditions, however I do not need to show the table to the user at any point nor do I need to save the table in a file. I only need to print said table via a printer and JTable seems overkill for such a task, not to mention rather complicated.
Is there a better alternative for this task?
Edit:
Yes, I need to print this to a Printer device.
The table is fairly simple, this is an example of it.
Table to output example

Related

How to design the appearance of text in mongodb?

I have a question and answer stored in the object. The request comes in the form of a question and I would like to get an attractive appearance of the text for the answer. For example, bold key words, or underlined words.
Is it possible to store such text in the mongo database, or will I have to create a java class that will process all keywords and edit them?
I think you should process the data in class as required.
Database responsibility is to keep the data not the fancy stuff

Plausibility of plan to use DOM4J with JTables & Action Listeners

I am preparing to embark on a large solo project at my place of employment. First let me describe the project. I have been asked to create a Java program that can take a CamT54 file (which is just a xml file) and have java display the information in table form. Then users should be given the ability to remove certain components from the table and have it go back to xml format with the changes.
I'm not well versed in dealing with XML in Java so this is going to be a learn and work task. Before I begin investing time I would like to know that my approach is the best approach.
My plan is to use DOM4J to do the parsing and handling of the xml. I will use a JTable to display the data and incorporate some buttons to the GUI that allow the modifications of the data through the use of some action listeners.
Would this be a plausible plan? Can DOM4J effectively allow xml data to be displayed in a table format and furthermore could that data be easily modified or deleted then resaved to a new xml?
I thought I would go ahead and answer this as I finished the program and wanted to post what I thought was the easiest solution in case anyone else needed help.
It turned out the easiest approach (for me at least) was to use the standard DOM parser, here are the steps I took.
Parsed the entire XML into String array lists. XPath was required for this, I also had to convert the elements into Strings and remove the extra tag information from the string using substrings since I only wanted the actual value.
I populated a JTable with these arrays.
Once users finished editing and clicked a save button then another Dom parser would take the original XML and change each and every attribute using the values from the Arrays (that were deleted and repopulated with the JTable cell values when the user clicked "save").

Binding multi-source data to GUI in Java

Thanks for taking time to read my question.
Here's my issue : I have different data files (.csv) that I need to basically cram into the same GUI. But there are some operations that I need to do on them, nothing really fancy though. And I figured those operations would really facilitated by the possibility of using the "Sort By" and "Group By". That's why I thought to import the .csv files as databases (they are actually databases exported into csv format).
So let's use a simple example : I used the SUM operation on a column, in addition to the Group By. And I want to display the result in, say, a JTable (or other), how should I proceed ? Keeping in mind that this operation must be done for each file, and I need to display the result from the others files in the same component.

Limit the significant figures in a uitable in Matlab. Data imported from Java

I have a table where I imported data using javaaddpath. I would like to limit the significant figures of this java database in Matlab.
I use javaaddpath to add the string I would like to work in and from there I select a database. Once in the database I fill a listbox with messages from the java database. From there I generate a template and check off the ones I would like to work with and hit a plot button. This populates a table with data (again, from the database in java). I would like to know how to limit the significant figures of the numbers that fill up that table.
format short
and
fprintf
aren't really relevant to me here because I'm trying to put the output into a table, which stores as a cell array. I'm currently working on trying the function
vpa(A,d)
but it doesn't accept a cell array or a matrix. I am willing to populate the table as normal, extract the data, format it, and then repopulate the table, I'm just unsure how to do so.
Any help or websites to point me to would be very much appreciated. I also posted this query on the Mathworks help forum (here), but haven't had any luck.
You can set the ColumnFormat property of the uitable to be any string that the format command accepts. For example, if your table has one column you can set the property to {'short g'} (it has to be a cell array, one value per column).
Note that although the format command accepts shortg, in some releases of MATLAB the ColumnFormat property only accepts short g with a space (I think this is a bug).
If you need a number of significant figure that is not provided by one of the options to the format command, the best solution I've found is to set all the column formats to char, and convert numerical contents to strings myself using the more flexible capabilities of sprintf.

Printing JTables without formatting of the original component

I'm writing an application which utilises tables which can be printed if the user so desires and I wish to print a JTable filled with data, except I haven't been able to find an option to remove the formatting; the printed tables looks like it does in the GUI (based on the system theme) which is making the table less readable and using excess ink.
I wish to print the same data with clear formatting. Is there a way to do this straight from a JTable or is my best option simply to print to a file and have the use printer from there. Currently it functions through a viewer which gives the user some options for printing, and then it goes to the system's printer.
Since 1.5, "Simple new print() methods allow for quick and easy addition of printing support to your application."

Categories