JTextArea w/Scroll bar wont scroll AND code drops through if statements

Hi, I'm still having trouble with the text area in the following code. When you run the code, you get the top arrow on the scroll bar, but the bottom is cut off. Also, a big problem is that no matter what choice is selected from the combo box, the code drops through to the last available value each time. Someone on the forums suggested using an array list for the values in the combo box, but I have not been able to figure out how to do that. A quick example would be apprciated.
Thank you in advance for any help
//Import required libraries
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;
//Create the class
public class Week3Assignment407B extends JFrame implements ActionListener
     //Panels used in container
     private JPanel jPanelRateAndTermSelection;         
     //Variables for Menu items
     private JMenuBar menuBar;    
     private JMenuItem exitMenuItem; 
     private JMenu fileMenu; 
     //Variables for user instruction and Entry       
     private JLabel jLabelPrincipal;   
     private JPanel jPanelEnterPrincipal;  
     private JLabel jLabelChooseRateAndTerm; 
     private JTextField jTextFieldMortgageAmt;
     //Variables for combo box and buttons
     private JComboBox TermAndRate;
     private JButton buttonCompute;
     private JButton buttonNew; 
     private JButton buttonClose;
     //Variables display output
     private JPanel jPanelPaymentOutput;
     private JLabel jLabelPaymentOutput;
     private JPanel jPanelErrorOutput;
     private JLabel jLabelErrorOutput;  
     private JPanel jPanelAmoritizationSchedule;
     private JTextArea jTextAreaAmoritization;
     // Constructor 
     public Week3Assignment407B() {            
          super("Mortgage Application");      
           initComponents();      
     // create a method that will initialize the main frame for the GUI
      private void initComponents()
          setSize(700,400);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
          Container pane = getContentPane();
          GridLayout grid = new GridLayout(15, 1);
          pane.setLayout(grid);       
          //declare all of the panels that will go inside the main frame
          // Set up the menu Bar
          menuBar = new JMenuBar();
          fileMenu = new JMenu();
          fileMenu.setText("File");        
          exitMenuItem = new JMenuItem(); 
           exitMenuItem.setText("Exit");
          fileMenu.add(exitMenuItem); 
          menuBar.add(fileMenu);       
          pane.add(menuBar);
          //*******************TOP PANEL ENTER PRINCIPAL*****************************//
          // Create a label that will advise user to enter a principle amount
          jPanelEnterPrincipal = new JPanel(); 
          jLabelPrincipal = new JLabel("Amt to borrow in whole numbers");
          jTextFieldMortgageAmt = new JTextField(10);
          GridLayout Principal = new GridLayout(1,2);
          jPanelEnterPrincipal.setLayout(Principal); 
            jPanelEnterPrincipal.add(jLabelPrincipal);
          jPanelEnterPrincipal.add(jTextFieldMortgageAmt);
          pane.add(jPanelEnterPrincipal);
          //****************MIDDLE PANEL CHOOSE INTEREST RATE AND TERM*****************//
          // Create a label that will advise user to choose an Int rate and term combination
          // from the combo box
          jPanelRateAndTermSelection = new JPanel();
          jLabelChooseRateAndTerm = new JLabel("Choose the Rate and Term");
          buttonCompute = new JButton("Compute Mortgage");
          buttonNew = new JButton("New Mortgage");
          buttonClose = new JButton("Close");
          GridLayout RateAndTerm = new GridLayout(1,5);
          //FlowLayout RateAndTerm = new FlowLayout(FlowLayout.LEFT);
          jPanelRateAndTermSelection.setLayout(RateAndTerm);
          jPanelRateAndTermSelection.add(jLabelChooseRateAndTerm);
          TermAndRate = new JComboBox();
          jPanelRateAndTermSelection.add(TermAndRate);
          TermAndRate.addItem("7 years at 5.35%");
          TermAndRate.addItem("15 years at 5.5%");
          TermAndRate.addItem("30 years at 5.75%");
          jPanelRateAndTermSelection.add(buttonCompute);
          jPanelRateAndTermSelection.add(buttonNew);
          jPanelRateAndTermSelection.add(buttonClose);
          pane.add(jPanelRateAndTermSelection);
          //**************BOTTOM PANEL TEXT AREA FOR AMORITIZATION SCHEDULE***************//
          jPanelAmoritizationSchedule = new JPanel();
          jTextAreaAmoritization = new JTextArea(26,50);
          // add scroll pane to output text area
               JScrollPane scrollBar = new JScrollPane(jTextAreaAmoritization, 
               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
          jPanelAmoritizationSchedule.add(scrollBar);
            pane.add(jPanelAmoritizationSchedule);
          //***************ADD THE ACTION LISTENERS TO THE GUI COMPONENTS*****************//
          // Add ActionListener to the buttons and menu item
          exitMenuItem.addActionListener(this);
          buttonCompute.addActionListener(this);         
          buttonNew.addActionListener(this);
          buttonClose.addActionListener(this);
          TermAndRate.addActionListener(this);
          jTextFieldMortgageAmt.addActionListener(this);
          //*************** Set up the Error output area*****************//
          jPanelErrorOutput = new JPanel();
          jLabelErrorOutput = new JLabel();
          FlowLayout error = new FlowLayout();
          jPanelErrorOutput.setLayout(error);
          pane.add(jLabelErrorOutput);
          setContentPane(pane);
          pack();
          setVisible(true);
     //Display error messages
     private void OutputError(String ErrorMsg){
          jLabelErrorOutput.setText(ErrorMsg);
          jPanelErrorOutput.setVisible(true);
     //create a method that will clear all fields when the New Mortgage button is chosen
     private void clearFields()
          jTextAreaAmoritization.setText("");
          jTextFieldMortgageAmt.setText("");
     //**************CREATE THE CLASS THAT ACTUALLY DOES SOMETHING WITH THE EVENT*****//
     //This is the section that receives the action source and directs what to do with it
     public void actionPerformed(ActionEvent e)
          Object source = e.getSource();
          String ErrorMsg;
          double principal;
          double IntRate;
          int Term;
          double monthlypymt;
          double TermInYears = 0 ;
          if(source == buttonClose)
               System.exit(0);
          if (source == exitMenuItem) {      
                   System.exit(0);
          if (source == buttonNew)
               clearFields();
          if (source == buttonCompute)
               //Make sure the user entered valid numbers
               try
                    principal = Double.parseDouble(jTextFieldMortgageAmt.getText());
               catch(NumberFormatException nfe)
                    ErrorMsg = (" You Entered an invalid Mortgage amount"
                              + " Please try again. Please do not use commas or decimals");
                    jTextAreaAmoritization.setText(ErrorMsg);
               principal = Double.parseDouble(jTextFieldMortgageAmt.getText());
                if (TermAndRate.getSelectedItem() == "7 years at 5.35%") ;
                    Term = 7;
                    IntRate = 5.35;
                if (TermAndRate.getSelectedItem()  == "15 years at 5.5%") ;
                    Term = 15;
                    IntRate = 5.5;
                if (TermAndRate.getSelectedItem() == "30 years at 5.75%") ;
                    Term = 30;
                    IntRate = 5.75;
               //Variables have been checked for valid input, now calculate the monthly payment
               NumberFormat formatter = new DecimalFormat ("$###,###.00");
               double intdecimal = intdecimal = IntRate/(12 * 100);
               int months = Term * 12;
               double monthlypayment = principal *(intdecimal / (1- Math.pow((1 + intdecimal),-months)));
               //Display the Amoritization schedule
               jTextAreaAmoritization.setText(" Loan amount of " + formatter.format(principal)
                                                + "\n"
                                                + " Interest Rate is " +  IntRate + "%"
                                        + "\n"
                                        + " Term in Years "  + Term
                                        + " Monthly payment "+  formatter.format(monthlypayment)
                                        + "\n"
                                        + "  Amoritization is as follows:  "
                                        + "------------------------------------------------------------------------");
     public Insets getInsets()
          Insets around = new Insets(35,20,20,35);
          return around;
     //Main program     
     public static void main(String[]args) { 
          Week3Assignment407B frame = new Week3Assignment407B(); 
   }

here's your initComponents with a couple of changes, the problem was the Gridlayout(15,1)
also, the scrollpane needed a setPreferredSize()
  private void initComponents()
    setSize(700,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Container pane = getContentPane();
    JPanel pane = new JPanel();
    //GridLayout grid = new GridLayout(15, 1);
    GridLayout grid = new GridLayout(2, 1);
    pane.setLayout(grid);
    menuBar = new JMenuBar();
    fileMenu = new JMenu();
    fileMenu.setText("File");
    exitMenuItem = new JMenuItem();
    exitMenuItem.setText("Exit");
    fileMenu.add(exitMenuItem);
    menuBar.add(fileMenu);
    //pane.add(menuBar);
    setJMenuBar(menuBar);
    jPanelEnterPrincipal = new JPanel();
    jLabelPrincipal = new JLabel("Amt to borrow in whole numbers");
    jTextFieldMortgageAmt = new JTextField(10);
    GridLayout Principal = new GridLayout(1,2);
    jPanelEnterPrincipal.setLayout(Principal);
      jPanelEnterPrincipal.add(jLabelPrincipal);
    jPanelEnterPrincipal.add(jTextFieldMortgageAmt);
    pane.add(jPanelEnterPrincipal);
    jPanelRateAndTermSelection = new JPanel();
    jLabelChooseRateAndTerm = new JLabel("Choose the Rate and Term");
    buttonCompute = new JButton("Compute Mortgage");
    buttonNew = new JButton("New Mortgage");
    buttonClose = new JButton("Close");
    GridLayout RateAndTerm = new GridLayout(1,5);
    jPanelRateAndTermSelection.setLayout(RateAndTerm);
    jPanelRateAndTermSelection.add(jLabelChooseRateAndTerm);
    TermAndRate = new JComboBox();
    jPanelRateAndTermSelection.add(TermAndRate);
    TermAndRate.addItem("7 years at 5.35%");
    TermAndRate.addItem("15 years at 5.5%");
    TermAndRate.addItem("30 years at 5.75%");
    jPanelRateAndTermSelection.add(buttonCompute);
    jPanelRateAndTermSelection.add(buttonNew);
    jPanelRateAndTermSelection.add(buttonClose);
    pane.add(jPanelRateAndTermSelection);
    jPanelAmoritizationSchedule = new JPanel();
    jTextAreaAmoritization = new JTextArea(26,50);
    JScrollPane scrollBar = new JScrollPane(jTextAreaAmoritization,
      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollBar.setPreferredSize(new Dimension(500,100));//<------------------------
    jPanelAmoritizationSchedule.add(scrollBar);
    getContentPane().add(pane,BorderLayout.NORTH);
    getContentPane().add(jPanelAmoritizationSchedule,BorderLayout.CENTER);
    exitMenuItem.addActionListener(this);
    buttonCompute.addActionListener(this);
    buttonNew.addActionListener(this);
    buttonClose.addActionListener(this);
    TermAndRate.addActionListener(this);
    jTextFieldMortgageAmt.addActionListener(this);
    jPanelErrorOutput = new JPanel();
    jLabelErrorOutput = new JLabel();
    FlowLayout error = new FlowLayout();
    jPanelErrorOutput.setLayout(error);
    //pane.add(jLabelErrorOutput);not worrying about this one
    //setContentPane(pane);
    pack();
    setVisible(true);
  }instead of
if (TermAndRate.getSelectedItem() == "7 years at 5.35%") ;
Term = 7;
IntRate = 5.35;
you would be better off setting up arrays
int[] term = {7,15,30};
double[] rate = {5.35,5.50,5.75};
then using getSelectedIndex()
int loan = TermAndRate.getSelectedIndex()
Term = term[loan];
IntRate = rate[loan];

Similar Messages

  • Itunes tool bar wont work and other questions please!!!!

    Hey!
    My itunes toolbar wont work, it seems completly useless. I was just wondering how you can get it working again as i used it all the time.
    Another question for u guys is, is there a way of making msn messenger regonise the music ur listening to on itunes. I pressed the "turn on what im listening to" button but that hasnt worked.
    Thanks you guys, you rock!

    Maybe you just haven't forced the toolbar to show itself. As far as I know it only shows itself AFTER you search for something. It filters the results. This makes it different from all the other "bars" everyone is familiar with, the kind that reside in, say, Firefox and are just always there.

  • *Help* Spry Horizontal Menu Bar wont show and cant seem to center it with rest of content

    Hey,
    I am a newbie to Dreamweaver and was wondering if someone can
    help me with the Spry Horizontal Menu Bar....
    http://www.djdanmatthews.net
    1) After moving mouse over diffrent areas of Spry menu bar
    the text seems to disapear or not show up?
    2) I can't seem to center content of Spry menu bar with rest
    of website?
    3) How do I ad a image (where also can I get it) to the Spry
    menu bar so it looks more professional &3d?
    Thanks so much,
    Dan

    *Bump

  • SharePoint 2010, unable to see the site vertical scroll bar in Safari and Mozilla Firefox

    Hi,
    I am not able to see the sharepoint site vertical scroll bar in Safari and Mozilla firefox in window OS as well as  Mac OS , even I have tried with various option of the browser but still not able to see the vertical scroll bar.
    I have tried to check with other sharepoint site in Windows OS and found that I can see others sites vertical scroll bar in Safari and Mozilla firefox , Please let me know why I am not able to see for my sharepoint sites.
    Thanks
    Roopak

    Screen in jammed or how it looks without vertical scroll bar ? Check with site master page if you have modified anything related to  vertical bar or else Try in other system and check if you are able to see vertical bar . 
    Let us know your result 
    Whenever you see a reply and if you think is helpful, click &quot;Vote As Helpful&quot;! And whenever you see a reply being an answer to the question of the thread, click &quot;Mark As Answer

  • Scroll bar goes crazy and active window jumps around in size - Help

    I've got iTunes 7.0.5 installed. If I use iTunes for any length of time, my system goes crazy. The scroll bar on whatever program I make active goes up and down like mad, while the content of the active window shrinks and magnifies in size multiple times a second. It's very bizarre and consistently happens only when I run iTunes for some length of time. I have no problem if I choose Windows Media Player. It's very disturbing, as I can no longer use iTunes. Any help in knowing how to fix the problem, or even to trouble shoot it further, would be greatly appreciated.

    Here are a couple of thoughts on the Timeline scrolling and other possible display issues:
    1.) make sure that you have the very latest video driver - the very latest
    2,) if you have Vista, turn Aero and Sidebar off
    3.) if you have Window Blinds, get the very latest version
    4.) if you have an InteliPoint mouse driver, try removing it, and using the standard Windows mouse driver instead*
    5.) if you have a laptop and both the touch-pad and a mouse are installed and ON, turn the touch-pad OFF
    These are some suggestions that might affect your display issues.
    Good luck,
    Hunt
    * The MS InteliPoint has caused many display issues with Adobe products. Most often, these have manifested themselves in flashing GUI's and similar, but other odd behaviors have been experienced. If the removal of InteliPoint does help, try the very latest version, but be ready to revert to the standard Windows mouse driver.

  • Help in integrating scroll bar between photoshop and dreamweaver

    Hello,
    I'm a newbie to integration of other adobe products with dreamweaver. However, i was able to figure out the part where i can finally integrate my design from photoshop to dreamweaver.
    Now my problem is that in my design i have a beautiful scroll bar. I can't seem to find an answer on the web for integrating the same design of this scroll bar into dreamweaver and make it functional in dreamweaver.
    Just a bit of background on what i did is that i sliced my pages in photoshop and imported them into dreamweaver and everything is good. The only thing that's missing is making this design functional and most importantly the scroll bar.
    Really appreciate anyone's help!!!

    Hi there,
      You can try using a jQuery custom scrollbar. They're pretty easy to set up and you can find them here:
    http://www.net-kit.com/jquery-custom-scrollbar-plugins/
      Once you find a plugin that is close to your design, it's just a matter of switching out color/images/etc.
    -Devon

  • TS2771 my ipod touch is stuck in a talking mode, and i have to double click everything and it wont scroll, and it tells me everything im doing

    my ipod touch is stuck in some kind of talking mode and wont scroll and i have to double click everything. how do i get it back to normal

    - Try triple clicking the Home button and then going to Settings>General>Accessibility and turn VoiceOver off
    - Next try connecting the iPod to the computer and going to the Summary pane for the iPod in iTunes. Click on Configure Universal Access and turn VoiceOver off.

  • How can I animate my sprite to run on scroll and stop when scrolling stops?

    I appreciate everyones help so far.
    I want my illustration of a man to "walk" through my composition as the user scrolls through it.
    I have a sprite created and have made it loop. What sort of code do I need to write to get it to move only on scroll and stop off scroll?
    Thank you guys so much!
    Johnathan

    Hi,
    Thank you for your post.
    Please check the following tutorials for scrolling effects in edge animate.
    http://www.heathrowe.com/adobe-edge-animate-simple-scrollbar-symbols/
    http://www.adobe.com/inspire/2014/01/parallax-edge-animate.html
    Regards,
    Devendra

  • Acrobat 9 flash/flex form scrolling and hand mouse pointer problems

    Hello.
    There is pdf file with embeded flash swf file inside. Main business logic has been implemented on flash: there are drop-down interactive menu and  navigation links.
    I've noticed 2 problems related to Acrobat (flash movie itself, standalone, works correctly):
    1. Scrolling over drop-down menu doesn't work: mouse wheel doesn't scroll content of drop-down form menu. So, I have to manually click on scroll bar.
    2. Hand mouse pointer over links losses "hand" icon. Hand icon shows for short period and then disappears but should be visible while mouse pointer is over a link.
    I managed to test these problems on Windows, MacOS with Acrobat Proffessional 9.0 and Acrobat Reader 9.1
    So, Is there any way to resolve these problems?
    Thanks in advance

    I'll take a look at these.  #1 is a known issue with Flash Player and is already being looked at, haven't heard about #2 though.

  • Partially stuck mouse trackpad affecting scroll and mouse use

    On my Macbook Pro Retina, I noticed the track pad kind of half stick in the lower left corner. It's almost like when the button would jam but a halfway catch i feel when i put light pressure on different parts of the trackpad.
    Ever since the partial stick my scrolling and use of the mouse is affected as if i had an extra finger down doing other things or moving more slowly... Or it'll scroll normal speed then slow down drastically and vice versa. I've tried restarting and noted that it's probably a physical issue because nothing help except very carefully trying to counter with pressure on the upper right area...
    Has this happened to anyone? How much is it gonna cost me to fix it? I just got this Macbook less than a year ago (Jan-Feb 2013) and I'm sad the trackpad is already giving me problems even though I RARELY actually CLICK with the button... How did the button manage to (partially) stick?

    Make an appointment with the genius bar at your local Apple Store.
    I had a similar problem, they replaced my trackpad and keyboard $285.00

  • How to restore scrolling and preference options for magic mouse?

    My Apple Magic Mouse has lost the ability to scroll the way it used to. When I open the mouse pane in System Preferences, the magic mouse options and video examples no longer display; just scrolling and tracking speed. I changed batteries, then also switched mice with a colleague, but still no horizontal or inertia scrolling, etc. I have tried restoring the PRAM several times, trashed the preference logs, etc, even reinstalled the system software.
    I'm using a MacBook Pro withSnow Leopard. I had previously downloaded USB Overdrive, and read somewhere that it could be the cause. I got rid of USB Overdrive, but my mouse still doesn't behave the way it used to. Any suggestions?

    I got rid of USB Overdrive
    And all its preference files?  Repaired permissions?
    Disconnect all peripherals from your computer.
    Boot from your install disc & run Repair Disk from the utility menu. To use the Install Mac OS X disc, insert the disc, and restart your computer while holding down the C key as it starts up.
    Select your language.
    Once on the desktop, select Utility in the menu bar.
    Select Disk Utility.
    Select the disk or volume in the list of disks and volumes, and then click First Aid.
    Click Repair Disk.
    Restart your computer when done.
    Repair permissions after you reach the desktop-http://support.apple.com/kb/HT2963 and restart your computer.

  • Zooming, scrolling and moving in large images

    I'd like to create a document viewer that works like Google Maps or Safari. Basically the "image" of the document is so big that I only want to load parts of it when the user actually goes over to that part of it.
    How can I enable zooming, scrolling and moving in "large" images like that?
    I looked for a tutorial or sample code, but I wasn't able to find anything.
    Any help would be appreciated,
    -Chris.

    I have 4 Gbyte of RAM. I tried to close every applications but the problem remains. You are right about Web Browser problems but unfortunately my problem is related with Finder windows too. I have 800 Mbyte of free RAM.
    Another fact I can say to you is that when I move Finder window (or other windows as I wrote before) the area outside the border of the window is repainted not well with puzzle effect. I think the problem is related to desktop refresh and repaint. It seems that graphic acceleration doesn't work for some window!!!!

  • Scrolling and Swipe funtionalities have stopped working since update.

    Since I have installed updates on my Mac the magic mouse settings now show just basic settings such as tracking speed, double-click speed and primary mouse button. As the title suggests scrolling and swiping are no longer working.
    I have tried to pair it a few times but nothing changes.
    Ideas?

    wuaw. its done. (:
    i reinstall USB OVERDRIVE and uninstall again. but i do in UTILITIES folder at this time. you should click 'Uninstall USB OVERDRIVE.app' in System Preferences > Utilities folder.

  • Scrolling and rightclicking with magic mouse doesnt  work anymore

    Suddenly scrolling and rightclicking with magic mouse doesnt work any more. Left clicking and cursor moving works normal. I have checked the system preferences for the mouse and find nothing strange or unchecked. Any ideas?

    Also tried the universal access thing. Doesnt work.

  • How to switch off scroll and zoom functions of touchpad on Satellite L

    Hi.
    Can anyone tell me how to switch off the scroll and zoom functions for the Synaptics Touchpad v7.2 .
    Can't seem to do it via the Control Panel.
    Any suggestions.

    Hi buddy,
    > Can't seem to do it via the Control Panel.
    You can only disable the virtual scrolling function if the touchpad driver is installed properly. The driver provides extended functions and allows you to disable/enable special features. If you dont have installed the touchpad driver download it on official Toshiba page:
    http://eu.computers.toshiba-europe.com > Support & Downloads > Download Drivers
    Then navigate to control panel as the previous user wrote for disabling the scroll function.
    Can you find it now?

Maybe you are looking for