Re: Writing to a file and a TextArea
- From: IchBin <weconsul@xxxxxxx>
- Date: Fri, 24 Feb 2006 17:53:59 -0500
zhah99 wrote:
Hello there! The application I am building will calculate the total sales for
any number of salesmen. The application will allow the salesman to enter
their name, the product (numbered 1-5 in a JComboBox) they sold as well as
the amount of products they sold. They would then hit the Salesman Entry Done
button to tell the application that the salesman is done entering their
information. Once all of the salesmen have entered their information they can
hit Grand Total and the grand total of those sales will display in the text
area.
If you replace and or add the code I include this will get you where you want to be. You will need to change the layout manager and component resizing but I'm sure you will not have a problem with that.. You may want to add your JTextArea into a scroll pane. This is normally the standard you do in most cases.
[snip code]
static NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
private static final StyledDocument document = new DefaultStyledDocument();
private static int offset = document.getLength();
`
[snip code]
output = new JTextArea(400, 200);
output = new JTextArea(document);
output.setOpaque(true);
output.setLineWrap(true);
output.setWrapStyleWord(true);
JScrollPane jScrollPane = new JScrollPane(output);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane.setOpaque(true);
jScrollPane.setSize(300, 300);
[snip code]
c.add(output);
c.add(jScrollPane);
[snip code]
Sales sale = new Sales();sale.pack();
sale.setSize(300,300);
sale.setVisible(true);[snip code]
[snip code]
outp += "\nTotal\t\t\t" + currencyFormat.format(total);
try {
SimpleAttributeSet sas = new SimpleAttributeSet();
sas.addAttribute(StyleConstants.Foreground, Color.BLUE);
document.insertString(offset, outp+ " \n", sas);
sas.removeAttribute(StyleConstants.Foreground);
offset = document.getLength();
} catch (BadLocationException ble) {
ble.printStackTrace();
}
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
.
- Follow-Ups:
- Re: Writing to a file and a TextArea
- From: zhah99 via JavaKB.com
- Re: Writing to a file and a TextArea
- References:
- Writing to a file and a TextArea
- From: zhah99
- Writing to a file and a TextArea
- Prev by Date: Re: how do I veto a setSelected() on JCheckBox
- Next by Date: Re: how do I veto a setSelected() on JCheckBox
- Previous by thread: Re: Writing to a file and a TextArea
- Next by thread: Re: Writing to a file and a TextArea
- Index(es):