Results 1 to 6 of 6
  1. #1
    Glyph is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default Problems Resizing TextArea

    I cant seem to resize a text area box.

    I tried resizing the text area and the panel that I put it in.

    What am I doing wrong?




    method
    Java Code:
         public JPanel createTextAreaPanel() {
            textArea = new TextArea();
            textArea.setSize(TEXT_AREA_FRAME_WIDTH, TEXT_AREA_FRAME_HEIGHT);
    
            JPanel panel = new JPanel();
            panel.add(textArea);
            panel.setSize(TEXT_AREA_FRAME_WIDTH, TEXT_AREA_FRAME_HEIGHT);
            return panel;
    
        }





    whole class
    Java Code:
      /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package tutor;
    
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.TextArea;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    /**
     *
     * @author bbeetle
     */
    public class GUI extends JFrame {
    
        private javax.swing.JButton enterButton;
        private javax.swing.JButton runReportButton;
        private javax.swing.JButton quitButton;
        private javax.swing.JLabel minutesLabel;
        private javax.swing.JLabel paymentLabel;
        private javax.swing.JTextField minutesTextField;
        private javax.swing.JTextField paymentTextField;
        private java.awt.TextArea textArea;
        private ActionListener enterListener;
        private ActionListener quitListener;
        private ActionListener runReportListener;
        private static final int FRAME_WIDTH = 500;
        private static final int FRAME_HEIGHT = 500;
        private static final int TEXT_AREA_FRAME_WIDTH = 500;
        private static final int TEXT_AREA_FRAME_HEIGHT = 400;
        private EarningsBucket data;
    
    
        public GUI(EarningsBucket mydata) {
    
           data = mydata;
           class enterListener implements ActionListener
           {
              public void actionPerformed(ActionEvent event)
              {
    
                    double minutes = Double.parseDouble(minutesTextField.getText());
                    double payment = Double.parseDouble(paymentTextField.getText());
                    data.recordSession(minutes, payment);
                    minutesTextField.setText("");
                    paymentTextField.setText("");
              }
           }
           class runReportListener implements ActionListener
           {
              public void actionPerformed(ActionEvent event)
              {
                 String rawData = data.runReport();
                 textArea.setText(rawData);
              }
           }
           class quitListener implements ActionListener
           {
              public void actionPerformed(ActionEvent event)
              {
                System.exit(0);
              }
           }
            enterListener = new enterListener();
            runReportListener = new runReportListener();
            quitListener = new quitListener();
    
            createWindow();
            setSize(FRAME_WIDTH, FRAME_HEIGHT);
        }
    
        public void createWindow() {
            JPanel textInputPanel = createTextInputPanel();
            JPanel textAreaPanel = createTextAreaPanel();
            JPanel buttonsPanel = createButtonsPanel();
    
    
            add(textInputPanel, BorderLayout.NORTH);
            add(textAreaPanel, BorderLayout.CENTER);
            add(buttonsPanel, BorderLayout.SOUTH);
    //        JPanel panel = new JPanel();
    //        panel.add(textInputPanel,BorderLayout.NORTH);
    //        panel.add(textAreaPanel,BorderLayout.CENTER);
    //        panel.add(buttonsPanel,BorderLayout.SOUTH);
    
    
    
        }
    
        public JPanel createTextAreaPanel() {
            textArea = new TextArea();
    //        textArea.setSize(TEXT_AREA_FRAME_WIDTH, TEXT_AREA_FRAME_HEIGHT);
    
            JPanel panel = new JPanel();
            panel.add(textArea);
            panel.setSize(TEXT_AREA_FRAME_WIDTH, TEXT_AREA_FRAME_HEIGHT);
            return panel;
    
        }
    
        public JPanel createButtonsPanel() {
            runReportButton = new JButton();
            runReportButton.setText("Run Report");
            runReportButton.addActionListener(runReportListener);
            
    
            quitButton = new JButton();
            quitButton.setText("Quit");
            quitButton.addActionListener(quitListener);
    
            JPanel panel = new JPanel();
            panel.add(runReportButton);
            panel.add(quitButton);
            return panel;
    
        }
    
        public JPanel createTextInputPanel() {
            minutesLabel = new JLabel();
            minutesLabel.setText("Time in Minutes");
            paymentLabel = new JLabel();
            paymentLabel.setText("Payment");
    
            minutesTextField = new JTextField();
            paymentTextField = new JTextField();
    
            enterButton = new JButton();
            enterButton.setText("Enter");
            enterButton.addActionListener(enterListener);
            
    
            JPanel panel = new JPanel();
            panel.setLayout(new GridLayout(3, 2));
            panel.add(minutesLabel);
            panel.add(minutesTextField);
            panel.add(paymentLabel);
            panel.add(paymentTextField);
            panel.add(enterButton);
    //        createTextInputPanel.setBorder(new TitledBorder(new EtchedBorder(), "Enter Info"));
    
            return panel;
        }
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    A panel's width and height is in pixels. A textarea's width and height is in columns and rows.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    A panel's width and height is in pixels. A textarea's width and height is in columns and rows.
    That's not true: only the JTextArea constructor considers those sizes as lines and colums, the setSize( ... ) method is just inherited from the Component class. The JPanels are equiped with LayoutManagers, I can understand that the JTextArea can't be resized at will.

    kind regards,

    Jos

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Oops. Sorry, had constructors on the mind.

  5. #5
    Glyph is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    Thanks! I see now that I just needed to specify columns and rows in the TextArea Constructor. After that -- setting the panels size that contains the TextArea seemed to have no effect.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Glyph View Post
    Thanks! I see now that I just needed to specify columns and rows in the TextArea Constructor. After that -- setting the panels size that contains the TextArea seemed to have no effect.
    That's not it; see my reply #3 where I not only mercilessly corrected Masijade's mistake but also gave a hint w.r.t. your problem.

    kind regards,

    Jos ;-)

Similar Threads

  1. button not resizing in awt
    By alinaqvi90 in forum AWT / Swing
    Replies: 1
    Last Post: 08-17-2010, 03:43 PM
  2. panel resizing
    By simo_mon in forum AWT / Swing
    Replies: 1
    Last Post: 08-15-2009, 02:09 PM
  3. JFrame resizing
    By carderne in forum New To Java
    Replies: 3
    Last Post: 07-22-2009, 07:42 PM
  4. Image resizing
    By alley in forum Java 2D
    Replies: 2
    Last Post: 11-13-2007, 10:10 AM
  5. problems when I print in textarea
    By gabriel in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •