Results 1 to 14 of 14
- 06-11-2012, 06:22 PM #1
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Adding a table of text to a TextArea
Hello all, I have to create a program that allows the user to enter the loan and loan period in the number of years from a text field, and should display
the monthly and total payments for each interest rate starting from 5 percent to 8 percent, with increments of one-eight, in a text area.My question is how do I put a table of text into a text area.Here is what I need.
Java Code:InterestRate monthlyPayment Totalpayment 5.0 188.71 11322.74 5.125 189.28 11357.13 .. .. .. and so on up to 8%.
- 06-11-2012, 06:24 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,441
- Rep Power
- 16
Re: Adding a table of text to a TextArea
I believe a JTextArea recognises HTML markup, so a <table> might work?
Please do not ask for code as refusal often offends.
- 06-11-2012, 06:33 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Re: Adding a table of text to a TextArea
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-11-2012, 06:42 PM #4
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Re: Adding a table of text to a TextArea
Thanks guys I use JFormDesiner to do my GUI and I could not figure out how to add a third coolum to the JTable am I missing something or do I have to do that with code.
- 06-11-2012, 07:27 PM #5
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Here is what I have come up with!
My question is how do I put this print statement on the GUi
What do you think would be the best way to add that print statement to a GUI.Java Code:public class Quiz2CApp { public static void main(String[] args) { LoanTable GUI = new LoanTable(); } } import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.GroupLayout; /* * Created by JFormDesigner on Mon Jun 11 11:50:51 CDT 2012 */ /** * @author Adam Ortell */ public class LoanTable extends JFrame { public LoanTable() { initComponents(); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license panel1 = new JPanel(); label1 = new JLabel(); textField1 = new JTextField(); label2 = new JLabel(); textField2 = new JTextField(); button1 = new JButton(); scrollPane1 = new JScrollPane(); //======== this ======== Container contentPane = getContentPane(); //======== panel1 ======== { //---- label1 ---- label1.setText("Loan Amount:"); //---- label2 ---- label2.setText("Number of Years:"); //---- button1 ---- button1.setText("Show Table"); GroupLayout panel1Layout = new GroupLayout(panel1); panel1.setLayout(panel1Layout); panel1Layout.setHorizontalGroup( panel1Layout.createParallelGroup() .addGroup(panel1Layout.createSequentialGroup() .addContainerGap() .addComponent(label1, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(label2, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE) .addGap(1, 1, 1) .addComponent(textField2, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addGap(50, 50, 50) .addComponent(button1, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE) .addGap(0, 19, Short.MAX_VALUE)) ); panel1Layout.setVerticalGroup( panel1Layout.createParallelGroup() .addGroup(panel1Layout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(panel1Layout.createParallelGroup() .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(label2) .addComponent(label1)) .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(button1)))) ); } GroupLayout contentPaneLayout = new GroupLayout(contentPane); contentPane.setLayout(contentPaneLayout); contentPaneLayout.setHorizontalGroup( contentPaneLayout.createParallelGroup() .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE) ); contentPaneLayout.setVerticalGroup( contentPaneLayout.createParallelGroup() .addGroup(contentPaneLayout.createSequentialGroup() .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)) ); pack(); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // Generated using JFormDesigner non-commercial license private JPanel panel1; private JLabel label1; private JTextField textField1; private JLabel label2; private JTextField textField2; private JButton button1; private JScrollPane scrollPane1; // JFormDesigner - End of variables declaration //GEN-END:variables class actionEventHandler implements ActionListener { public void actionPerformed(ActionEvent actionEvent) { double numerator; double denominator; double b, e; double numYears; double principal; System.out.println("Loan Amount: "); principal = Double.parseDouble(textField1.getText()); System.out.println("Number of Years: "); numYears = Double.parseDouble(textField2.getText()); System.out.println("Interest Rate | Monthly Payment | Total Payment"); for ( double intRate = 5; intRate <= 8; intRate = Math.round((intRate + .125) * 1000.0)/1000.0 ) { numerator = intRate/100.0 * principal / 12; e = -(12 * numYears); b = (intRate/100.0 / 12) + 1.0; denominator = 1.0 - Math.pow(b, e); System.out.println( intRate + "% | $" + Math.round((numerator / denominator)*100.0) / 100.0 + " | $" + Math.round(((numerator / denominator) * 12 * numYears) * 100.0) / 100.0); } } } }
Thanks alot guys.
- 06-11-2012, 07:53 PM #6
- 06-11-2012, 08:26 PM #7
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Re: Here is what I have come up with!
I have figured it out now I am just trying to get the columns aligned with the Interest and monthly payments. I always feel like that GUI designer was cheating my teacher swears by them.Thanks for the tip.
- 06-11-2012, 08:32 PM #8
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Re: Adding a table of text to a TextArea
Thanks I always though that was cheating but my teacher swears by them. I figured it out , but is there a way to format JtextArea.appends output like you can with
printf.
- 06-12-2012, 10:11 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,441
- Rep Power
- 16
Re: Adding a table of text to a TextArea
Please do not ask for code as refusal often offends.
- 06-12-2012, 05:41 PM #10
Member
- Join Date
- Jun 2012
- Location
- St.louis, Missouri
- Posts
- 49
- Rep Power
- 0
Re: Adding a table of text to a TextArea
It was a requirement to use a textArea.Which I still don't understand being how it could not be formatted correctly.Thanks for all the help guys.
- 06-12-2012, 06:01 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,441
- Rep Power
- 16
Re: Adding a table of text to a TextArea
If you use printf to generate the strings then that might help.
That way you could sort out padding at least.
Then just append that string to the area?Please do not ask for code as refusal often offends.
- 06-12-2012, 06:11 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Re: Adding a table of text to a TextArea
And: use a fixed width font (possibly in combination with tabs instead of spaces).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-12-2012, 06:13 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,441
- Rep Power
- 16
Re: Adding a table of text to a TextArea
I only ever think in terms of fixed width...I have a mono-spaced mind.
:)Please do not ask for code as refusal often offends.
- 06-12-2012, 06:29 PM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Re: Adding a table of text to a TextArea
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Displaying text in textarea with a button
By brendan89 in forum New To JavaReplies: 1Last Post: 11-29-2011, 04:53 PM -
show text file to textArea
By louboulos in forum New To JavaReplies: 14Last Post: 06-12-2011, 01:16 PM -
Adding to TextArea
By nawl in forum New To JavaReplies: 10Last Post: 05-21-2010, 07:56 AM -
how to display text with \n,\r in jsp from textarea?
By tejz in forum New To JavaReplies: 0Last Post: 02-25-2010, 11:30 AM -
Appending text to TextArea
By deepthought015 in forum AWT / SwingReplies: 3Last Post: 05-01-2009, 02:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks