Results 1 to 6 of 6
Thread: Problems Resizing TextArea
- 10-19-2010, 12:28 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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; } }
- 10-19-2010, 12:42 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
A panel's width and height is in pixels. A textarea's width and height is in columns and rows.
- 10-19-2010, 12:58 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 10-19-2010, 01:21 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Oops. Sorry, had constructors on the mind.
- 10-19-2010, 01:26 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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.
- 10-19-2010, 01:55 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
button not resizing in awt
By alinaqvi90 in forum AWT / SwingReplies: 1Last Post: 08-17-2010, 03:43 PM -
panel resizing
By simo_mon in forum AWT / SwingReplies: 1Last Post: 08-15-2009, 02:09 PM -
JFrame resizing
By carderne in forum New To JavaReplies: 3Last Post: 07-22-2009, 07:42 PM -
Image resizing
By alley in forum Java 2DReplies: 2Last Post: 11-13-2007, 10:10 AM -
problems when I print in textarea
By gabriel in forum New To JavaReplies: 1Last Post: 07-26-2007, 06:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks