Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How can i adjust TextArea size automatically

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can i adjust TextArea size automatically

    [Consider the program below]

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package scheduling;

    /**
    *
    * @author ThankGod
    */
    import javax.swing.*;
    import java.awt.event.*;
    public class DualQuery extends JFrame implements ActionListener
    {
    JMenuBar jmb = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenuItem exe = new JMenuItem("Execute Query",new ImageIcon("execute.jpg"));
    JPanel querypanel = new JPanel();
    JPanel resultpanel = new JPanel();
    JTextArea textArea = new JTextArea(10,60);
    JLabel resultlabel = new JLabel(" Query Result");

    public DualQuery()
    {

    textArea.setText("Query");
    resultpanel.add(resultlabel);
    exe.addActionListener(this);
    file.add(exe);
    jmb.add(file);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane. VERTICAL_SCROLLBAR_ALWAYS);
    querypanel.add(scrollPane);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, querypanel, resultpanel);
    splitPane.setOneTouchExpandable(true);
    getContentPane().add(splitPane);
    setSize(700, 650);// here's the part where i center the jframe on screen
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    }//end of constructor
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==exe){
    //Executing Engine here
    MySQLController mysql = new MySQLController(resultpanel,textArea.getText());

    }
    }//end main
    }

    public class MySQLController(JPanel panel,String query){
    JLabel fname = new JLabel("First Name:");
    JTextField nametf = new JTextField();

    public MySQLControler(){
    panel.add(fname);
    panel.add(namef);
    jpanel.add(fname);
    }

    }
    1. I want the content of the firstname label and text field from the MySQLController class to automatically updated in the DualQuery class when a user click on execute menuitem But its not given me the desired result

    2. Is it possible to make the JTextArea's size adjust automatically when the user adjust the splitpane up and down?


  2. #2
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: How can i adjust TextArea size automatically

    Indent your code and wrap code blocks around it for readability.

    1. What results are you expecting? What results have been produced?

    2. Yes it is possible to adjust the size of a JTextArea.

    Java API: JTextArea

    java.awt.TextArea has two properties rows and columns that are used to determine the preferred size. JTextArea uses these properties to indicate the preferred size of the viewport when placed inside a JScrollPane to match the functionality provided by java.awt.TextArea. JTextArea has a preferred size of what is needed to display all of the text, so that it functions properly inside of a JScrollPane. If the value for rows or columns is equal to zero, the preferred size along that axis is used for the viewport preferred size along the same axis.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can i adjust TextArea size automatically

    1. Actually i am expecting records to be read from MySQL table, placed in the resultpanel and automatically updated in the resultpanel of the main class.

    2. Yes. But when you scroll down the split pane, you see empty panel under the textarea instead of the textarea adjusting automatically to fill the space

Similar Threads

  1. Can't adjust width of the X.
    By Kris45 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 9th, 2013, 07:12 PM
  2. Jpanel preffered size exceed the nactual screen size
    By manish.ctae@gmail.com in forum AWT / Java Swing
    Replies: 2
    Last Post: October 31st, 2012, 01:29 AM
  3. [SOLVED] TextArea Not Setting size?
    By Java Programmer in forum AWT / Java Swing
    Replies: 4
    Last Post: January 22nd, 2012, 11:52 AM
  4. [SOLVED] JTables: How do I adjust row order as I drag columns?
    By assel in forum AWT / Java Swing
    Replies: 3
    Last Post: December 7th, 2010, 04:51 PM
  5. how to adjust the size on a graphic component
    By Khoatic in forum AWT / Java Swing
    Replies: 8
    Last Post: November 19th, 2010, 11:28 PM