Adding JScrollPane to JInternalFrame

Hello, I have been having a rather difficult time adding a a jscrollpane to my jinternalframe. I have a panel that I am adding some objects to. I add that panel to a jscrollpane, then add the jscrollpane to the container of the JInternalFrame. I get no errors, but when I run this thing, the panel spills out over the JInternalFrame, the panel is bigger than the internal frame. When I take the jscrollpane off of it and just add the panel directly to the JInternalFrame, it fits jsut fine. However, I need the scrollbar to view all of the material. Any ideas? Here is a piece of my code.
         JInternalFrame internal = new JInternalFrame("New Tree",true,true,true,true);
      Container c = internal.getContentPane();
//this panel is something I created earlier and have added stuff to it
//panel is of the type java.awt.panel
        panel.setBackground(Color.white);
        JScrollPane jsp = new JScrollPane();
        jsp.setViewportView(panel);
        c.add(jsp);
        internal.setSize(700,400);
        internal.setOpaque(true);
        internal.setVisible(true);
//I add it to a desktop pane a little later on

Here's an example:
import java.awt.*;
import javax.swing.*;
public class InternalFrameTest extends JFrame {
     private JInternalFrame internalFrame1;
     private JInternalFrame internalFrame2;
     private JScrollPane scrollPane;
     private JDesktopPane desktopPane;
     public InternalFrameTest() {
          try {
               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               desktopPane = new JDesktopPane();
               scrollPane = new JScrollPane(desktopPane);
               desktopPane.setPreferredSize(new Dimension(350, 250));
               internalFrame1 = new JInternalFrame();
               desktopPane.add(internalFrame1);
               internalFrame1.setBounds(30, 30, 100, 100);
               internalFrame1.setVisible(true);
               internalFrame2 = new JInternalFrame();
               desktopPane.add(internalFrame2);
               internalFrame2.setBounds(150, 100, 100, 100);
               internalFrame2.setVisible(true);
               getContentPane().add(scrollPane, BorderLayout.CENTER);
               pack();
               setSize(300, 200);
               setLocationRelativeTo(null);
               setVisible(true);
          } catch (Exception e) { e.printStackTrace(); }
     public static void main(String[] args) { new InternalFrameTest(); }
}

Similar Messages

  • JTable, JScrollPane, and JinternalFrame problems.

    I have this internal frame in my application that has a scrollpane and table in it. Some how it won't let me selelct anything in the table. Also it scrolls really weird. There's a lot of chopping going on. Here's my code for the internal frame:
    public class BCDEObjectWindow extends javax.swing.JInternalFrame{
        private Vector bcdeObjects = new Vector();
        private DefaultTableModel tModel;
        public BCDEObjectWindow(JavaDrawApp p) {
            initComponents();
            this.setMaximizable(false);
            this.setClosable(false);
            this.setIconifiable(true);
            this.setDoubleBuffered(true);
            objectTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
            listScrollPane.setColumnHeaderView(new ObjectWindowHeader());
            pack();
            this.setVisible(true);
            parent = p;
            getAllBCDEFigures();
            setPopupMenu();
            tModel = (DefaultTableModel) objectTable.getModel();
            objectTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        public void getAllBCDEFigures() {
            bcdeObjects.removeAllElements();
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
        public void addBCDEFigure(BCDEFigure b) {
            bcdeObjects.add(b);
            tModel.addRow(new Object[]{b.BCDEName, "incomplete"});
        public void changeLabelName(BCDEFigure b) {
            if (bcdeObjects.contains(b)) {
                int index = bcdeObjects.indexOf(b);
                tModel.removeRow(index);
                tModel.insertRow(index, new Object[]{b.BCDEName, "incomplete"});
        public void removeBCDEFigure(BCDEFigure b) {
            int index = 0;
            if (bcdeObjects.contains(b)) {
                index = bcdeObjects.indexOf(b);
                bcdeObjects.remove(b);
                tModel.removeRow(index);
        public void removeAllBCDEFigures(){
            int i;
            for (i = 0; i < bcdeObjects.size(); i++) {
                tModel.removeRow(0);
            bcdeObjects.removeAllElements();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            listScrollPane = new javax.swing.JScrollPane();
            objectTable = new javax.swing.JTable();
            getContentPane().setLayout(new java.awt.FlowLayout());
            setBackground(new java.awt.Color(255, 255, 255));
            setIconifiable(true);
            setTitle("BCDE Objects");
            listScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            listScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            listScrollPane.setPreferredSize(new java.awt.Dimension(250, 150));
            objectTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                new String [] {
                    "Name", "Status"
                boolean[] canEdit = new boolean [] {
                    true, false
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
            objectTable.setColumnSelectionAllowed(true);
            listScrollPane.setViewportView(objectTable);
            jPanel1.add(listScrollPane);
            getContentPane().add(jPanel1);
            pack();
        }// </editor-fold>
        // Variables declaration - do not modify
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane listScrollPane;
        private javax.swing.JTable objectTable;
        // End of variables declaration
    }and this is how i create the object in my JFrame:
    bcdeOW = new BCDEObjectWindow(this);
            bcdeOW.setLocation(400, 0);
            if (getDesktop() instanceof JDesktopPane) {
                ((JDesktopPane)getDesktop()).setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                ((JDesktopPane)getDesktop()).add(bcdeOW, JLayeredPane.PALETTE_LAYER);
            } else
                getDesktop().add(bcdeOW);Any help would be great. Thanks a lot.

    Rajb1 wrote:
    to get the table name to appear
    create a scollpane and put the table in the scrollpane and then add the the scollpane to the component:
    //declare
    scrollpane x;
    //body code
    scrollpane x - new scrollpane();
    table y = new table();
    getContentPane().add(x(y));What language is this in, the lambda calculus -- add(x(y))!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Adding JScrollPane to CardLayout

    public static void panelLayout (String panel)
            cardPanel.add (Rosters.rosterPanel1, "roster1");
            cardPanel.add (Rosters.rosterPanel2, "roster2");
            cardPanel.add (OP300.evalLoadPane1, "op300load1"); // JScrollPane with JPanel inside
            cardPanel.add (mainPanel, "main");
            CardLayout showPanel = (CardLayout)(cardPanel.getLayout ());
            showPanel.show (cardPanel, panel);
        }I'm trying to add a JScrollPane to my CardLayout just like I have with the other JPanels. All of the other JPanels work fine, but adding the JScrollPane is giving me issues. As soon as PanelLayout() is called, even if it isn't calling for the JScrollPane, I'm getting: Exception occurred during event dispatching:
    java.lang.NullPointerException
            at java.awt.Container.addImpl(Container.java:1027)
            at java.awt.Container.add(Container.java:903)
            at HubEvals.panelLayout(HubEvals.java:540)
            at Login.b_loginActionPerformed(Login.java:175)
            at Login.access$000(Login.java:18)
            at Login$1.actionPerformed(Login.java:92)
            ...The JScrollPane modifier is public static so it isn't having problems getting access to it. I even tried putting the JScrollPane inside a JPanel so it would be like:
    - JPanel
    ----- JScrollPane
    ---------- JPanel (panel that is longer than the frame itself, hence why it's in a scroll pane)
    I still got the same error.

    This time I remembered to initialize it. I added it to my initComponents() method and I was still getting the problem:public HubEvals ()
            initComponents ();
            new Rosters ();
            new OP300 ();
            RegisterLogin intro = new RegisterLogin ();
            intro.showInDialog (this);
        }I had accidentally typed new OP3O0 (); instead of new OP300 ();. What's up with that? The first thing I typed doesn't even exist as a method, class, or variable and it still passed NetBeans validation. I spent well over 50 minutes on a stupid '0' being an 'O' and the 2 characters look exactly the same in the code font.
    Anyway, thanks. Problem solved. Heh. You run into stuff like this when you don't leave the computer for hours at a time.

  • Adding JScrollPane on JPanel??Is there any problem.??

    hi,
    I have a JPanel over which i added a JScrollPane on to whose view portvie i added a JTable.
    But the problem is the table is not getting visble.Not only table all the components i add to scrollpane which on a panel is not getting displayed.
    Am i missing something??
    final JScrollPane scrollPane = new JScrollPane();
              panel.add(scrollPane);
              table = new JTable();
              scrollPane.setViewportView(table);

    Make sure to add the panel to the content pane as well.
    If the problem still persists, then please post a simple executable demo program that demonstrates the behavior.

  • Adding JScrollPane to a JList problems

    Hi,
    I am having problem in trying to add a JScrollPane to a JList, it doesnt appear i don't understand what i am doing wrong.
    private String [] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
    private JList main = new JList(mainMenu);
    private JScrollPane scrolling = new JScrollPane(main);
    public Mobile()
             main.setLocation(60, 110);
             main.setSize(90, 50);
             add(scrolling);
             scrolling.setVisible(true);
    }

    The code to run the app is:
    import java.awt.*;
    import javax.swing.*;
    class MobileGUI {
         public static void main(String[] args) {
              JFrame frame = new JFrame("Mobile Phone Simulation");
              Container pane = frame.getContentPane();
              pane.add(new Mobile());
              frame.setSize(340, 625);
              frame.show();
    }The class that contains the components is:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    class Mobile extends JComponent {
    private String[] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
    private JList main = new JList(mainMenu);
    private JScrollPane scrolling = new JScrollPane(main);
    public JTextArea display = new JTextArea(6, 30);
    public MobileGUI()
              //Displays
              setLayout(null);
              //Display for messages
              display.setLocation(120, 60);
              display.setSize(90, 50);
              add(display);
              display.setVisible(false);
              //MainMenu Jlist Display
              main.setLocation(120, 60);
              main.setSize(90, 50);
              add(scrolling);
              scrolling.setVisible(true);
         public void paint(Graphics g) {
         g.setColor(Color.gray.brighter());
         g.fillRoundRect(30, 30, 270, 530, 40, 20);
         g.setColor(Color.black);
         g.fillArc(30, 30, 270, 320, 0, 180);
        g.fillArc(30, -180, 270, 740, 180, 180);
         g.setColor(Color.gray);     
         super.paint(g);       
    }The JList does not appear neither does the JScrollPane

  • Adding JScrollPane doesn't work... hmm....

        private void jbInit() throws Exception {
            this.getContentPane().setLayout(null);
            this.setSize(new Dimension(400, 300));
            this.setTitle("All Videos Own By Store");
            ta_show.setBounds(new Rectangle(30, 25, 320, 220));
            ta_show.setEditable(false);
            ta_show.setEnabled(false);
            JScrollPane scrollingArea = new JScrollPane(ta_show);
            getContentPane().add(scrollingArea);
            this.getContentPane().add(ta_show, null);
            //this.getContentPane().add(scrollingArea);
            this.setVisible(true);
        }ta_show is the JTextArea...
    I will load a text file into the JTextArea and it should show the JScrollPane since the text file is quite large... But it doesn't show..
    Any ideas?

    try this for size:
        private void jbInit()
            JPanel p = new JPanel();
            p.setPreferredSize(new Dimension(400, 300));
            p.setLayout(new BorderLayout());
            int eb = 20;
            p.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            ta_show.setPreferredSize(new Dimension(800, 600)); // or however big you want it
            ta_show.setEditable(false);
            //ta_show.setEnabled(false);
            JScrollPane scrollpane = new JScrollPane(ta_show);
            p.add(scrollpane, BorderLayout.CENTER);
            getContentPane().add(p);
        }

  • How do I get at a JTable on a JInternalFrame?

    I've been working on this Multiple Document Interface application, and things have been great up to this point. The user chooses to run a "report" and then selects an entity to get the info for. I then hit the database. Each row returned from the database query goes into it's own data object, which is added to an ArrayList in my custom table model, and that ArrayList is used to generate the JTable, which is then added to a ScrollPane, which is then added to the JInternalFrame, which is then added to the JDesktop pane. Good stuff, right?
    I'm now trying to add Print functionality, and I'm at a loss. What I want to do is have the user do the standard File->Print, which will print out the JTable on the currently selected inner frame. I can get a JTable to print using JTable.print(). What I can't do is find a way to get the JTable from the selected frame.
    I can get the selected frame using desktop.getSelectedFrame(), but I'm at a loss as to what to do next. I've played around with .getComponent, but I'm not having any luck. the components returned don't seem to do me any good...for example, JViewPort?
    Am I going about this the wrong way? Have I poorly designed this? Am I missing the obvious?
    Thanks,
    -Adam

    Well, if you only have a single component on the internal frame then you can use getComponent(0). But then you need to go up the parent chain to get the actual table. You will initially get the JScrollPane, then use that to get the JViewport and then use that to get the viewport component.
    Another option is to extend the JInternalFrame class and insted using the add method to add a component you create get/setTable(...) methods. Then you can save the table as a class variable before adding it the scrollpane and adding the scrollpane to the internal frame.

  • How to add a KeyListener to a JInternalFrame

    1). I have Main Window which is an Application window and has a menu. When I click on a menu option,
    a user interface which is a JInternalFrame type, with JTextFields in it, is loaded.
    2). In the first JTextField(e.g. Employee Number), I have a KeyListener added to the JInternalFrame.
    3). When I enter an Employee number in the JTextField and press the Key F10, I have to fetch the details about the Employee
    (his first name, middle name, last name etc.) from the database and display these details in the corresponding
    JTextFields in the user interface.
    PROBLEM:
    I am able to add a KeyListener to the JInternalFrame but it does not work the way I need it to.
    The moment F10 key is pressed, the JInternalFrame looses focus, and the focus goes to the Main Window and does not execute
    the code for the keyPressed event that is there in the listener.
    How do I overcome this issue??
    The code that I am using is below
    public class TD {
    public void invoke(){
    cFrame = new JInternalFrame("TD Form",
    false, //resizable
    true, //closable
    true, //maximizable
    true);//iconifiable
    // More code here..................
    //Destroy the TD Window.
    cFrame.addInternalFrameListener(new InternalFrameAdapter() {
         public void internalFrameClosing(InternalFrameEvent evt){
                   cancelSteps();
    }); // end of InternalFrameListener.
    cFrame.addKeyListener(new KeyTD(this)); // Adding the KeyListener here to the JInternalFrame
    cFrame.setVisible(true);
    cFrame.setSize(800,450);
    cFrame.setLocation(10,10);
    } // end of the constructor.
    // Inner class that implements the KeyListener
    class KeyTD implements KeyListener {
    private int msg =JOptionPane.INFORMATION_MESSAGE;
    private String title = "KeyPress Event Message";
    Container cornbut;
    TD objTD;
    private int UTNum;
    public KeyTD(TD objTD){
              this.objTD = objTD;
    public void keyPressed(KeyEvent ke){
    int key1 = ke.getKeyCode();
    switch(key1){
    case KeyEvent.VK_F9:
    tD_F9();
    break;
    case KeyEvent.VK_F10:
    UTNum = getNum(); // Reads the content of the JTextField and gets the Integer value
    if (UTNum > 0){
                        tD_F10();
    }else{
    JOptionPane.showMessageDialog(cornbut," Please enter the Number. ",title,msg);
    break;
    }//end of keyPressed method
    public void keyReleased(KeyEvent ke){
    public void keyTyped(KeyEvent ke){
    public void tD_F9(){
    //sets focus to the Text Field where the key listener has been added
    }//end of tD_F9 method
    public void tD_F10(){
    String str = String.valueOf(UTNum);
    Objdbdef.fetchTaskDefiner(str,"", "","" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" );
    if(//there are records in the database then){                       
    // If there are records matching the number from the JTextField the display statements are here.........
    }else{
    JOptionPane.showMessageDialog(cornbut,"There are no records found for the specified criteria.",title,msg);
    }//end of td_F10 method
    }// end of KeyTD class

    As a rule of thumb, I never use KeyListeners, unless you want to listen to many different key strokes.
    Instead, use ActionMap/InputMap. You can attach an action to, say your desktop, that
    is activated when F1 is pressed WHEN_ANCESTOR_OF_FOCUSED_COMPONENT or
    WHEN_IN_FOCUSED_WINDOW

  • Error using JsplitPane in JInternalFrame...help...

    Hi,
    If I am adding JSplitPane to JInternalFrame, I am getting the following run time error:
    Any suggestions.. appreciated.
    Thanks....
    java.lang.NullPointerException: peer
    at sun.awt.windows.WCanvasPeer.create(Native Method)
    at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:366)
    at sun.awt.windows.WCanvasPeer.<init>(WCanvasPeer.java:26)
    at sun.awt.windows.WToolkit.createCanvas(WToolkit.java:283)
    at java.awt.Canvas.addNotify(Canvas.java:76)
    at java.awt.Container.addNotify(Container.java:1579)
    at javax.swing.JComponent.addNotify(JComponent.java:4015)
    at java.awt.Container.addNotify(Container.java:1579)
    at javax.swing.JComponent.addNotify(JComponent.java:4015)
    at java.awt.Container.addNotify(Container.java:1579)
    at javax.swing.JComponent.addNotify(JComponent.java:4015)
    at java.awt.Container.addNotify(Container.java:1579)
    at javax.swing.JComponent.addNotify(JComponent.java:4015)
    at javax.swing.JRootPane.addNotify(JRootPane.java:483)
    at java.awt.Container.addNotify(Container.java:1579)
    at javax.swing.JComponent.addNotify(JComponent.java:4015)
    at java.awt.Container.addImpl(Container.java:374)
    at javax.swing.JLayeredPane.addImpl(JLayeredPane.java:201)
    at java.awt.Container.add(Container.java:284)
    at javax.swing.JLayeredPane.setLayer(JLayeredPane.java:343)
    at javax.swing.JLayeredPane.setPosition(JLayeredPane.java:424)
    at javax.swing.JLayeredPane.moveToFront(JLayeredPane.java:395)
    at javax.swing.JInternalFrame.moveToFront(JInternalFrame.java:1024)
    at javax.swing.JInternalFrame.toFront(JInternalFrame.java:1499)
    at javax.swing.JInternalFrame.show(JInternalFrame.java:1457)
    at java.awt.Component.show(Component.java:946)
    at java.awt.Component.setVisible(Component.java:903)
    at javax.swing.JComponent.setVisible(JComponent.java:1885)
    at Client.Init(Client.java:835)
    at Client.<init>(Client.java:659)
    at Client.main(Client.java:974)

    Hi, please post some code, if this do not help you.
    At line 835 in the class Client, Method init ( Client.Init(Client.java:835) ) the varibale peer is null.
    Have you forgotten to intialize peer before Init is called??
    Greetings
    Michael

  • Problem in refreshing jinternalframe

    Hello,
    In java code I have added jtable to jinternalframe and
    on each button click I have to show new values filled in jtable which is in jinternalframe.But I am getting new jinternalframe next to original jinternalframe.I want new jinternalframe to be superimposed on previous.What is solution to this?
    code:
    buttonNext.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    System.out.println("rowno"+tableActual.getRowCount());
    if(i<tableActual.getRowCount())
    String s1=tableActual.getValueAt(i,1).toString();
    System.out.println("s1:"+s1);
    tableVirtual.table.setValueAt(s1,i,1);
    System.out.println("s1 in vtable:"+tableVirtual.table.getValueAt(i,1));
    stepLabel.setText("Calculating Gen"+tableVirtual.table.getValueAt(i,1));
    String s2=tableActual.getValueAt(i,2).toString();
    tableVirtual.table.setValueAt(s2,i,2);
    stepLabel.setText("Calculating Kill"+tableVirtual.table.getValueAt(i,1));
    i=i+1;
    System.out.println("i="+i);
    tableVirtual.showTable();
    desktop.remove(frame);
    JInternalFrame frame = new JInternalFrame("SimpleTableDemo",true,true,true,true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tableVirtual.setOpaque(true); //content panes must be opaque
    frame.setContentPane(tableVirtual);
    //Display the window.
    frame.pack();
    frame.setLocation(0,451);
    frame.setVisible(true);
    desktop.add(frame);
    });

    I have tried it. But its giving next internal frame of half size than previous one.
    And new jinternalframe is still in background of previous one.What to do to take it to front?I have tried jinternalframe.front().But it has no effect.

  • Problem on JScrollPane

    I'm trying to put some JLabel to a JPanel and then put it into a JScrollPane but somehow I dont see any JScrollBar appear anywhere...is there something wrong that I did?Or do I have to manually set a scrollbar ?.. I have try manually put in one but still got the same result...I did read some example on it but it works for them, when I try to do the exactly the same thing in my code...it fails....
    JLabel a = new JLabel("a");
    JLabel b = new JLabel("b");
    JLabel c = new JLabel("c");
    JPanel contain = new JPanel(new GridLayout(3,1));
    contain.add(a);
    contain.add(b);
    contain.add(c);
    JScrollPane AScroll = new JScrollPane()
    AScroll.add(contain);thx for the help

    First of all, thank you for your suggetion..
    After I try your method of doing it..I still get the same result...Here is my actual code..
              NewLayout = new GridLayout(2 * NumOfRiding,2);
              NewLayout.setVgap(4);
              InfoTextPanel.setLayout(NewLayout);
              InfoTextPanel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
              for(int i = 0; i < NumOfRiding; i++){
                   CandNameLabel = new JLabel("Canditate " + (i+1) + " Name");
                   InfoTextPanel.add(CandNameLabel);    //first label add into infotextpanel
                   CandNameText = new JTextField(10);     
                   CandVector.add(CandNameText);
                   InfoTextPanel.add(CandNameText);     //a TextField add into infotextpanel
                   PartyLabel = new JLabel("Party");
                   InfoTextPanel.add(PartyLabel);          //another label add into a infotextpanel
                   PartyNameList = new JComboBox(PartyName);
                   CandPartyVector.add(PartyNameList);
                   InfoTextPanel.add(PartyNameList);     //a combobox added into the infotextpanel
                   InfoPanel.add(InfoTextPanel);          //the infoTextPanel is add into InfoPanel so more InfoTexPanel add be added
              JScrollPane AScroll = new JScrollPane();
              AScroll.setViewportView(InfoPanel);And After this.. I have to put this scrollpane into another panel and then into the actual windows...

  • JScrollPane packs in a wrong way.

    I've an JInternalFrame in wich I've a JScrollPane wich contains a JPanel, wich contains something.
    When I finished to create all , I pack() the JInternalFrame in order to make it as big as it contains all ..
    Doing that I see something wich is smaller then I need and then I see scrollbars.
    In normal situations this is not what I want..
    I used scrollPane in order to leave the user free to resize the IFrame and when the screen is not enough for all contents but in the normal situation I dont want it.
    Why pack does that "error".
    Did I miss something ?
    Tks
    Tullio

    Code? You presume that the scrollpane's perferred size will reflect the preferred size of the panel? I'm not sure that's the case. How about doing this?
    Dimension dim = new Dimension(500, 400);
    JPanel panel = new JPanel();
    panel.setPreferredSize(dim.width, dim.height);
    JScrollPanel scroll = new JScrollPane(panel);
    JInternalFrame jif = new JInternalFrame("frame 1", true, true, true, true);
    jif.getContentPane().add(scroll, BorderLayout.CENTER);
    jif.pack();
    Insets insets = jif.getInsets();
    jif.setSize(dim.width + insets.left + insets.right, dim.height + insets.top + insets.bottom);
    jif.setVisible(true);
    desktop.add(jif);

  • Need to change pgm to add graphics to deskpane (desk) not the overlay panel

    Hello everybody.
    I recently had help in adding graphics to my program and I unintentionally requested that my graphics be added to a overlay panel. After further development I realized that I actually need the graphics to be painted to jdeskpane DESK. I assume that by doing this that the graphics will remain where I placed them (relative to the associated frames) when the scrollbar is utilized.
    This might be a simple question, but I am new to graphics. Once I have the answer, I will analyze it and educate my self further.
    Thank you in advance,
    BAJH
    * Copyright (c) 2007 BAH
    * All rights reserved.
    package com.newsystem.common;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import java.beans.PropertyVetoException;
    import javax.swing.*;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JList;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.UIManager;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class A_Test_of_Frame_Connectors extends JDesktopPane {
         private static final long serialVersionUID = 1L;
         JDesktopPane desk;
         JScrollPane scrollpane;
         JInternalFrame iframe;
         JFrame frame;
         JList jList1;
         String currentframetitle;
         String currentframetip;
         String title;
         Integer maxwidth;
         Boolean definingsecondaryconnector;
         Boolean definingparentsecondaryconnector;
         Boolean definingchildsecondaryconnector;
         Rectangle secondaryparentrectangle;
         Rectangle secondarychildrectangle;
        double barb = 10.0;
        double phi = Math.toRadians(20.0);
        RenderingHints hints;
        Boolean drawline = false;
        Integer connectorcount;
        String[] connectiontype;
        String[] connectorparentframe;
        String[] connectorchildframe;
        JInternalFrame[] allframes;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHints(hints);
            g2.setPaint(Color.blue);
            if (drawline){
                  drawConnector(g2, secondaryparentrectangle, secondarychildrectangle);
        private void drawConnector(Graphics2D g2,Rectangle r1,Rectangle r2) {
            double dx = r2.getCenterX() - r1.getCenterX();
            double dy = r2.getCenterY() - r1.getCenterY();
            double theta = Math.atan2(dy, dx);
            Point2D.Double p1 = getIntersectionPoint(r1, theta);
            Point2D.Double p2 = getIntersectionPoint(r2, theta+Math.PI);
            Line2D.Double line = new Line2D.Double(p1, p2);
            drawArrowHeads(line, g2);
            g2.draw(line);
         public A_Test_of_Frame_Connectors(){
            hints = new RenderingHints(null);
            hints.put(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);
            hints.put(RenderingHints.KEY_STROKE_CONTROL,
                      RenderingHints.VALUE_STROKE_PURE);
              definingsecondaryconnector = false;
              frame = new JFrame("All Frames in a JDesktopPane Container");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              scrollpane = new JScrollPane(desk,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(new java.awt.Dimension(9925, 9580));
              desk = new JDesktopPane();
              desk.setPreferredSize(new java.awt.Dimension(15000, 30000));
                   int i = 5;
                   for (int j = 1; j <= i; j++){
                        UIManager.getDefaults().put("InternalFrame.icon", "");
                             ListModel jList1Model =
                                  new DefaultComboBoxModel(
                                            new String[] { "Item One" });
                             title = "Frame " + j;
                             jList1 = new JList();
                             jList1.setModel(jList1Model);
                        jList1.setBounds(1, 1, 45, 54);
                        jList1.setEnabled(false);
                        iframe = new JInternalFrame("Internal Frame: " + j, false, false, false, false);
                        iframe.setName(String.valueOf(j));
                        iframe.setTitle(title);
                        Integer titlewidth;
                        if (title.length() < 30){
                             titlewidth = 265;
                        else{
                             titlewidth = title.length()*8 + 20;
                        iframe.setBounds(j*20, j*20,titlewidth , j*18 + 35);
                        iframe.add(jList1);
                        iframe.addInternalFrameListener(new InternalFrameListener(){
                             public void internalFrameClosing(InternalFrameEvent e) {}
                             public void internalFrameClosed(InternalFrameEvent e) {}
                             public void internalFrameOpened(InternalFrameEvent e) {}
                             public void internalFrameIconified(InternalFrameEvent e) {}
                             public void internalFrameDeiconified(InternalFrameEvent e) {}
                             public void internalFrameActivated(InternalFrameEvent e) {
                                  currentframetitle = e.getInternalFrame().getTitle();
                                  currentframetip = e.getInternalFrame().getToolTipText();
                                  // Connectors
                                  if (definingsecondaryconnector.equals(true)){
                                       if (definingparentsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondaryparentrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            System.out.println("f name - "+e.getInternalFrame().getName());
                                            definingparentsecondaryconnector = false;
                                            definingchildsecondaryconnector = true;
                                       } else {
                                       if (definingchildsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondarychildrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            // draw connector
                                               drawline = true;
                                               repaint();
                                               definingchildsecondaryconnector = false;
                             public void internalFrameDeactivated(InternalFrameEvent e) {}
                        iframe.setToolTipText("Internal Frame :" + j);
                        iframe.setVisible(true);
                        desk.add(iframe);
              scrollpane.setViewportView(desk);
              JMenuBar menubar = new JMenuBar();
              JButton SecondaryConnector = new JButton("Secondary Connector");
              SecondaryConnector.addMouseListener(new java.awt.event.MouseAdapter() {
                   public void mousePressed(java.awt.event.MouseEvent e) {
                        definingsecondaryconnector = true;
                        definingparentsecondaryconnector = true;
                        definingchildsecondaryconnector = false;                    
                        try {
                             desk.getSelectedFrame().setSelected(false);
                        } catch (PropertyVetoException e1) {
                             // TODO Auto-generated catch block
                             e1.printStackTrace();
              JPanel overlayPanel = new JPanel();
                 OverlayLayout overlay = new OverlayLayout(overlayPanel);
                 overlayPanel.setLayout(overlay);
                 this.setOpaque(false);
                 overlayPanel.add(this);
                 overlayPanel.add(scrollpane);
              menubar.add(SecondaryConnector);
              frame.setJMenuBar(menubar);
    //          frame.add(scrollpane);
              frame.add(overlayPanel);
              scrollpane.setVisible(true);
              frame.setSize(800,600);
              frame.setVisible(true);
        private Point2D.Double getIntersectionPoint(Rectangle r, double theta) {
            double cx = r.getCenterX();
            double cy = r.getCenterY();
            double w = r.getWidth()/2;
            double h = r.getHeight()/2;
            double radius = Point2D.distance(0,0,w,h);
            double x = cx + radius * Math.cos(theta);
            double y = cy + radius * Math.sin(theta);
            Point2D.Double p = new Point2D.Double();
            int outcode = r.outcode(x, y);
            switch(outcode) {
                case Rectangle2D.OUT_TOP:             // 2
                    p.x = cx - h*((x - cx)/(y - cy));
                    p.y = cy - h;
                    break;
                case Rectangle2D.OUT_LEFT:            // 1
                    p.x = cx - w;
                    p.y = cy - w*((y - cy)/(x - cx));
                    break;
                case Rectangle2D.OUT_BOTTOM:          // 8
                    p.x = cx + h*((x - cx)/(y - cy));
                    p.y = cy + h;
                    break;
                case Rectangle2D.OUT_RIGHT:           // 4
                    p.x = cx + w;
                    p.y = cy + w*((y - cy)/(x - cx));
                    break;
                default:
                    System.out.println("Non-cardinal outcode: " + outcode);
            return p;
        private void drawArrowHeads(Line2D.Double line, Graphics2D g2) {
            double dy = line.getY2() - line.getY1();
            double dx = line.getX2() - line.getX1();
            double theta = Math.atan2(dy, dx);
            drawArrowHead(line.getP2(), theta, g2);
            drawArrowHead(line.getP1(), theta+Math.PI, g2);
        private void drawArrowHead(Point2D tip, double theta, Graphics2D g2) {
            double x = tip.getX() - barb * Math.cos(theta+phi);
            double y = tip.getY() - barb * Math.sin(theta+phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
            x = tip.getX() - barb * Math.cos(theta-phi);
            y = tip.getY() - barb * Math.sin(theta-phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
         public static void main(String[] args) {
              A_Test_of_Frame_Connectors d = new A_Test_of_Frame_Connectors();
    }

    Hello everybody.
    I recently had help in adding graphics to my program and I unintentionally requested that my graphics be added to a overlay panel. After further development I realized that I actually need the graphics to be painted to jdeskpane DESK. I assume that by doing this that the graphics will remain where I placed them (relative to the associated frames) when the scrollbar is utilized.
    This might be a simple question, but I am new to graphics. Once I have the answer, I will analyze it and educate my self further.
    Thank you in advance,
    BAJH
    * Copyright (c) 2007 BAH
    * All rights reserved.
    package com.newsystem.common;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import java.beans.PropertyVetoException;
    import javax.swing.*;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JList;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.UIManager;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class A_Test_of_Frame_Connectors extends JDesktopPane {
         private static final long serialVersionUID = 1L;
         JDesktopPane desk;
         JScrollPane scrollpane;
         JInternalFrame iframe;
         JFrame frame;
         JList jList1;
         String currentframetitle;
         String currentframetip;
         String title;
         Integer maxwidth;
         Boolean definingsecondaryconnector;
         Boolean definingparentsecondaryconnector;
         Boolean definingchildsecondaryconnector;
         Rectangle secondaryparentrectangle;
         Rectangle secondarychildrectangle;
        double barb = 10.0;
        double phi = Math.toRadians(20.0);
        RenderingHints hints;
        Boolean drawline = false;
        Integer connectorcount;
        String[] connectiontype;
        String[] connectorparentframe;
        String[] connectorchildframe;
        JInternalFrame[] allframes;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHints(hints);
            g2.setPaint(Color.blue);
            if (drawline){
                  drawConnector(g2, secondaryparentrectangle, secondarychildrectangle);
        private void drawConnector(Graphics2D g2,Rectangle r1,Rectangle r2) {
            double dx = r2.getCenterX() - r1.getCenterX();
            double dy = r2.getCenterY() - r1.getCenterY();
            double theta = Math.atan2(dy, dx);
            Point2D.Double p1 = getIntersectionPoint(r1, theta);
            Point2D.Double p2 = getIntersectionPoint(r2, theta+Math.PI);
            Line2D.Double line = new Line2D.Double(p1, p2);
            drawArrowHeads(line, g2);
            g2.draw(line);
         public A_Test_of_Frame_Connectors(){
            hints = new RenderingHints(null);
            hints.put(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);
            hints.put(RenderingHints.KEY_STROKE_CONTROL,
                      RenderingHints.VALUE_STROKE_PURE);
              definingsecondaryconnector = false;
              frame = new JFrame("All Frames in a JDesktopPane Container");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              scrollpane = new JScrollPane(desk,
                        ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(new java.awt.Dimension(9925, 9580));
              desk = new JDesktopPane();
              desk.setPreferredSize(new java.awt.Dimension(15000, 30000));
                   int i = 5;
                   for (int j = 1; j <= i; j++){
                        UIManager.getDefaults().put("InternalFrame.icon", "");
                             ListModel jList1Model =
                                  new DefaultComboBoxModel(
                                            new String[] { "Item One" });
                             title = "Frame " + j;
                             jList1 = new JList();
                             jList1.setModel(jList1Model);
                        jList1.setBounds(1, 1, 45, 54);
                        jList1.setEnabled(false);
                        iframe = new JInternalFrame("Internal Frame: " + j, false, false, false, false);
                        iframe.setName(String.valueOf(j));
                        iframe.setTitle(title);
                        Integer titlewidth;
                        if (title.length() < 30){
                             titlewidth = 265;
                        else{
                             titlewidth = title.length()*8 + 20;
                        iframe.setBounds(j*20, j*20,titlewidth , j*18 + 35);
                        iframe.add(jList1);
                        iframe.addInternalFrameListener(new InternalFrameListener(){
                             public void internalFrameClosing(InternalFrameEvent e) {}
                             public void internalFrameClosed(InternalFrameEvent e) {}
                             public void internalFrameOpened(InternalFrameEvent e) {}
                             public void internalFrameIconified(InternalFrameEvent e) {}
                             public void internalFrameDeiconified(InternalFrameEvent e) {}
                             public void internalFrameActivated(InternalFrameEvent e) {
                                  currentframetitle = e.getInternalFrame().getTitle();
                                  currentframetip = e.getInternalFrame().getToolTipText();
                                  // Connectors
                                  if (definingsecondaryconnector.equals(true)){
                                       if (definingparentsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondaryparentrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            System.out.println("f name - "+e.getInternalFrame().getName());
                                            definingparentsecondaryconnector = false;
                                            definingchildsecondaryconnector = true;
                                       } else {
                                       if (definingchildsecondaryconnector.equals(true)){
                                            // Build dummy rectangle for creating connector                         
                                            secondarychildrectangle = new Rectangle(e.getInternalFrame().getBounds());
                                            // draw connector
                                               drawline = true;
                                               repaint();
                                               definingchildsecondaryconnector = false;
                             public void internalFrameDeactivated(InternalFrameEvent e) {}
                        iframe.setToolTipText("Internal Frame :" + j);
                        iframe.setVisible(true);
                        desk.add(iframe);
              scrollpane.setViewportView(desk);
              JMenuBar menubar = new JMenuBar();
              JButton SecondaryConnector = new JButton("Secondary Connector");
              SecondaryConnector.addMouseListener(new java.awt.event.MouseAdapter() {
                   public void mousePressed(java.awt.event.MouseEvent e) {
                        definingsecondaryconnector = true;
                        definingparentsecondaryconnector = true;
                        definingchildsecondaryconnector = false;                    
                        try {
                             desk.getSelectedFrame().setSelected(false);
                        } catch (PropertyVetoException e1) {
                             // TODO Auto-generated catch block
                             e1.printStackTrace();
              JPanel overlayPanel = new JPanel();
                 OverlayLayout overlay = new OverlayLayout(overlayPanel);
                 overlayPanel.setLayout(overlay);
                 this.setOpaque(false);
                 overlayPanel.add(this);
                 overlayPanel.add(scrollpane);
              menubar.add(SecondaryConnector);
              frame.setJMenuBar(menubar);
    //          frame.add(scrollpane);
              frame.add(overlayPanel);
              scrollpane.setVisible(true);
              frame.setSize(800,600);
              frame.setVisible(true);
        private Point2D.Double getIntersectionPoint(Rectangle r, double theta) {
            double cx = r.getCenterX();
            double cy = r.getCenterY();
            double w = r.getWidth()/2;
            double h = r.getHeight()/2;
            double radius = Point2D.distance(0,0,w,h);
            double x = cx + radius * Math.cos(theta);
            double y = cy + radius * Math.sin(theta);
            Point2D.Double p = new Point2D.Double();
            int outcode = r.outcode(x, y);
            switch(outcode) {
                case Rectangle2D.OUT_TOP:             // 2
                    p.x = cx - h*((x - cx)/(y - cy));
                    p.y = cy - h;
                    break;
                case Rectangle2D.OUT_LEFT:            // 1
                    p.x = cx - w;
                    p.y = cy - w*((y - cy)/(x - cx));
                    break;
                case Rectangle2D.OUT_BOTTOM:          // 8
                    p.x = cx + h*((x - cx)/(y - cy));
                    p.y = cy + h;
                    break;
                case Rectangle2D.OUT_RIGHT:           // 4
                    p.x = cx + w;
                    p.y = cy + w*((y - cy)/(x - cx));
                    break;
                default:
                    System.out.println("Non-cardinal outcode: " + outcode);
            return p;
        private void drawArrowHeads(Line2D.Double line, Graphics2D g2) {
            double dy = line.getY2() - line.getY1();
            double dx = line.getX2() - line.getX1();
            double theta = Math.atan2(dy, dx);
            drawArrowHead(line.getP2(), theta, g2);
            drawArrowHead(line.getP1(), theta+Math.PI, g2);
        private void drawArrowHead(Point2D tip, double theta, Graphics2D g2) {
            double x = tip.getX() - barb * Math.cos(theta+phi);
            double y = tip.getY() - barb * Math.sin(theta+phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
            x = tip.getX() - barb * Math.cos(theta-phi);
            y = tip.getY() - barb * Math.sin(theta-phi);
            g2.draw(new Line2D.Double(tip.getX(), tip.getY(), x, y));
         public static void main(String[] args) {
              A_Test_of_Frame_Connectors d = new A_Test_of_Frame_Connectors();
    }

  • Problem in Painting in JDesktopPane

    Hi
    Here is the code for my class:
    public class DiagramPane extends JDesktopPane{
    public DiagramPane() {
    setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    public void paint(Graphics g){
    super.paint(g);
    int cmpCount=getComponentCount();
    if(cmpCount>1){
    for(int i=0;i<cmpCount-1;i++){
    Component cmp1=getComponent(i);
    Component cmp2=getComponent(i+1);
    g.drawLine(cmp1.getX(),cmp1.getY(),cmp2.getX(),cmp2.getY());
    public static void main(String[] s){
    JFrame f=new JFrame();
    DiagramPane dgrPane= new DiagramPane();
    JScrollPane scr=new JScrollPane(dgrPane);
    JInternalFrame lst1=new JInternalFrame("Frame1");
    JInternalFrame lst2=new JInternalFrame("Frame2");
    lst1.setBounds(150,150,100,100);
    lst2.setBounds(300,300,100,100);
    lst1.show();
    lst2.show();
    f.getContentPane().add(scr);
    dgrPane.add(lst1);
    dgrPane.add(lst2);
    f.setSize(400,400);
    f.show();
    Run this code and try to move any of the two InternalFrames. The lines need to be repainted accurately but this doesn't happen. This happens due to background filling of dirty region in JLayeredPane paint method. Can anyone tell me, what I should do so as to make these lines repaint properly. Lines are not in dirty region.
    Thanks in advance.
    Anil.

    You need your own DesktopManager that triggers a repaint after dragging ends, like:
    class MyDesktopManager extends DefaultDesktopManager {
    public void endDraggingFrame(JComponent comp) {
         super.endDraggingFrame(comp);
         repaint();
    then use it in your custom DesktopPane
    public DiagramPane() {
    setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    setDesktopManager(new MyDesktopManager());
    Greetings
    Jeanette

  • Losing my mind with a scrollpane

    Hello all. I am trying to get a scroll pane to work in an application that I have built for school. I am trying to get an amortization table to scroll through for a mortgage calculator. It isn't recognizing my scrollpane and I am not sure why. Could someone give me a push in the right direction.
    import javax.swing.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.text.*;
    public class MortCalcWeek3 extends JFrame implements ActionListener
         DecimalFormat twoPlaces = new DecimalFormat("#,###.00");//number format
         int L[] = {7, 15, 30};
         double I[] = {5.35, 5.5, 5.75};
         double P, M, J, H, C, Q;
         JPanel panel = new JPanel ();//creates the panel for the GUI
         JLabel title = new JLabel("Mortgage Calculator");
         JLabel PLabel = new JLabel("Enter the mortgage amount: ");
         JTextField PField = new JTextField(10);//field for obtaining user input for mortgage amount
         JLabel choices = new JLabel ("Choose the APR and Term in Years");
         JTextField choicestxt = new JTextField (0);
         JButton calcButton = new JButton("Calculate");
         JTextField payment = new JTextField(10);
         JLabel ILabel = new JLabel("Annual Percentage Rate: choose one");
         String [] IChoice = {I[0] + "", I[1] + "", I[2] + ""};
         JComboBox IBox = new JComboBox(IChoice);
         JLabel LLabel = new JLabel("Term (in years): choose one");
         String [] LChoice = {L[0] + "", L[1] + "", L[2] + ""};
         JComboBox LBox = new JComboBox(LChoice);
         JLabel amortBox = new JLabel("Amortiaztion Table");
         JScrollPane amortScroll = new JScrollPane();
         public MortCalcWeek3 () //creates the GUI window
                        super("Mortgage Calculator");
                        setSize(300, 400);
                        panel.setBackground (Color.white);
                        panel.setLayout(null);
                        panel.setPreferredSize(new Dimension(500, 500));
                        setResizable(false) ;
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        //Creates the container
                        Container contentPane = getContentPane();
                        FlowLayout fresh = new FlowLayout(FlowLayout.LEFT);
                        panel.setLayout(fresh);
                        //identifies trigger events
                        calcButton.addActionListener(this);
                        PField.addActionListener(this);
                        IBox.addActionListener(this);
                        LBox.addActionListener(this);
                        panel.add(PLabel);
                        panel.add(PField);
                        panel.add(choices);
                        panel.add(choicestxt);
                        panel.add(ILabel);
                        panel.add(IBox);
                        IBox.setBackground (Color.white);
                        panel.add(LLabel);
                        panel.add(LBox);
                        LBox.setBackground (Color.white);
                        panel.add(calcButton);
                        calcButton.setBackground (Color.white);
                        panel.add(payment);
                        payment.setBackground (Color.white);
                        panel.add(amortBox);
                        payment.setEditable(false);
                        panel.add(amortScroll);
                        setContentPane(panel);
                        setVisible(true);
         }// end of GUI info
              public void actionPerformed(ActionEvent e) {
                   MortCalcWeek3();     //calls the calculations
              public void MortCalcWeek3() {     //performs the calculations from user input
                   double P = Double.parseDouble(PField.getText());
                   double I = Double.parseDouble((String) IBox.getSelectedItem());
                   double L = Double.parseDouble((String) LBox.getSelectedItem());
                   double J = (I  / (12 * 100));//monthly interest rate
                   double N = (L * 12);//term in months
                   double M = (P * J) / (1 - Math.pow(1 + J, - N));//Monthly Payment
                 String showPayment = twoPlaces.format(M);
                 payment.setText(showPayment);
         //public void amort() {
                   //int N = (L * 12);
                   int month = 1;
                             while (month <= N)
                                  //performs the calculations for the amortization
                                  double H = P * J;//current monthly interest
                                  double C = M - H;//monthly payment minus monthly interest
                                  double Q = P - C;//new balance
                                  P = Q;//sets loop
                                  month++;
                                  String showAmort = twoPlaces.format(H + C + Q);
                                amortScroll(showAmort);
              public static void main(String[] args) {
              MortCalcWeek3 app = new MortCalcWeek3();
    }//end main
    }//end the programI am getting an error stating that it cannot resolve the symbol and it is reffering to my "amortScroll(showAmort);" statement. Please help.

    a scrollpane generally contains another component e.g. in this a JTextArea,
    where you can display the output of your while().
    try these changes
    1)
    JLabel amortBox = new JLabel("Amortiaztion Table");
    JTextArea ta = new JTextArea();//<----------------------added
    //JScrollPane amortScroll = new JScrollPane();//<-------changed to below line
    JScrollPane amortScroll = new JScrollPane(ta);
    2)
    panel.add(amortScroll);
    amortScroll.setPreferredSize(new Dimension(275,100));//<----------added
    setContentPane(panel);
    setVisible(true);
    3)
    String showAmort = twoPlaces.format(H + C + Q);
    //amortScroll(showAmort);//<---------------changed to below line
    ta.append(showAmort+"\n");

Maybe you are looking for

  • Crystal Report 2008 doesn't set  page size when export to excel file

    Hi, I am using Crystal Report 2008 Developer edition. At Crystal report design time setting the below page setup: Page Options -    to A3(297X420 mm) Orientation --- Landscape and using the following code in .net (c#) I am using below format options

  • Solution manager 7.1 - AS Java - no page displayed after login

    Hello friends, I am facing a strange issue in our solution manager system wherein the startpage is displayed (http://<hostname>:50000) but no page is displayed after login. User credentials are accepted (Username/Password invalid dialogue is not disp

  • Oracle 9i Forms - Display Insert Statements

    I'm getting an Oracle error "unable to insert record" during runtime of the 9i forms. Is there a way to display the insert statements? In 3.0 or 4.5 you can press F1 and F2 key how about in 9i ? thanks

  • Connection finally fixed, thanks BT!

    After weeks and weeks of having a bad connection I had a total loss of connection, after a bad morning with openreach not showing up the nice guy at BT actually got someone out that night to fix my connection. This is the end result http://www.speedt

  • Mkinitcpio and consolefont hook

    Hi there. I am trying to use font ter-112n in early userspace. I have tried doing what the wiki says about fonts. I've set CONSOLEFONT="ter-112n" in /etc/rc.conf I've rebuilt the kernel image using mkinitcpio -p kernel26 But when I boot up I get some