Sign in to follow this  
Enerjak

properly formating the text from the image (need help)

Recommended Posts

Enerjak    277
[url="http://puu.sh/1nA8n"]http://puu.sh/1nA8n[/url]

As you can see from this image, the current print out of the hardware store is suppose to be like that but I got it like this:

[url="http://puu.sh/1nA7i"]http://puu.sh/1nA7i[/url]


here is the code that prints the hardware store.

[CODE]
public void printReport()
{
// get the hardware stock from the store.
HardwareStock stock = store.getStock();

int length = stock.listSize();

String message = " ";

HardwareItem item = null;

message ="itemID ItemName pOrdered pInstore pSold manuPrice selling Price \n";
if(store.getFileLoaded() || length > 0)
{
for(int index = 0; index < length; index++)
{
item = stock.elementAt(index);

message += String.format("%d %s %d %d %d %.2f %.2f%n", item.getItemID(), item.getItemName(), item.getNumOfPartsOrdered(),
item.getNumOfPartsLeft(), item.getNumOfPartsSold(), item.getManufactuaterPrice(), item.getStoreSellingPrice());

}
this.reportTA.setText(message);
}
}
[/CODE]

please let me know if there's anything else you need.

Share this post


Link to post
Share on other sites
ppgamedev    311
Try setting a monospaced font.
Lucida Console, Courier New, etc... or just the default Font.MONOSPACED font.
Check the java.awt.GraphicsEnvironment and java.awt.Font javadocs for info on how to get a Font.

Other option (nicer) is to use a JTable. Edited by ppgamedev

Share this post


Link to post
Share on other sites
Enerjak    277
[quote name='ppgamedev' timestamp='1352325385' post='4998603']
Try setting a monospaced font.
Lucida Console, Courier New, etc... or just the default Font.MONOSPACED font.
Check the java.awt.GraphicsEnvironment and java.awt.Font javadocs for info on how to get a Font.

Other option (nicer) is to use a JTable.
[/quote]

a JTable sounds good now i need to see how to use it. TO GOOGLE

Share this post


Link to post
Share on other sites
ppgamedev    311
Sun created some very good tutorials on Java. They are still available from Oracle:
http://docs.oracle.com/javase/tutorial/index.html

And here is the specific part related to JTable:
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

Share this post


Link to post
Share on other sites
Enerjak    277
[quote name='ppgamedev' timestamp='1352327212' post='4998622']
Sun created some very good tutorials on Java. They are still available from Oracle:
[url="http://docs.oracle.com/javase/tutorial/index.html"]http://docs.oracle.c...rial/index.html[/url]

And here is the specific part related to JTable:
[url="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html"]http://docs.oracle.c...ents/table.html[/url]
[/quote]

Thanks, I actually just tried my self and got this:

[url="http://puu.sh/1nD85"]http://puu.sh/1nD85[/url]

now naturally that's all the items from the list and. Here is what i did:

[CODE]
// print the report (if there's anything in it.)
public void printReport()
{
// get the hardware stock from the store.
HardwareStock stock = store.getStock();

int length = stock.listSize();

String message = " ";

double TotalValue = 0.0;
int totalStock = 0;
HardwareItem item = null;

String[] colunmNames =
{
"Item ID",
"Item Name",
"pOrdered",
"pInStock",
"pSold",
"Manufacturer Price",
"Store selling price"
};

Object[][] data = null;

if(store.getFileLoaded() || length > 0)
{
for(int index = 0; index < length; index++)
{
item = stock.elementAt(index);

Object[][] data2 =
{
{ item.getItemID(),
item.getItemName(),
item.getNumOfPartsOrdered(),
item.getNumOfPartsLeft(),
item.getNumOfPartsSold(),
item.getManufactuaterPrice(),
item.getStoreSellingPrice()
}
};

this.reportTable.setModel(new DefaultTableModel(data2, colunmNames));

}


}


}

[/CODE]

the program has 8 entries in the list so far, but it only shows one, am I on th right track?

Share this post


Link to post
Share on other sites
Enerjak    277
[quote name='ppgamedev' timestamp='1352329599' post='4998634']
You're making the same mistake you made before with the combobox.
Do you remember?
[/quote]

I think so.......hmmm, let me see.

Share this post


Link to post
Share on other sites
Enerjak    277
[quote name='ppgamedev' timestamp='1352329599' post='4998634']
You're making the same mistake you made before with the combobox.
Do you remember?
[/quote]

the moron strikes again!! but seriously i got it, thanks

Share this post


Link to post
Share on other sites
ppgamedev    311
First time the code was given to you.
Second time just a hint.
Well done!
I bet next time you'll solve it by yourself.
This is called "learning process" and you're doing it fine. Congratulations

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this