Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Why I got such big (in vertical size) single-line JtextField in my app?

    I composed rather simple GUI
    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JTextField;      
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.BoxLayout;
    //import javax.swing.Container;
    import java.awt.GridLayout; 
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.io.*;
    
    public class Jr extends JFrame {
        int ind;
        JFrame frame;
        static JLabel label;
        JPanel contentPane;
        static JTextArea textArea;
        static JTextField textField;
         
        public Jr() {
        frame = new JFrame();
        frame.setDefaultLookAndFeelDecorated(true);
        frame.setTitle("File Indexator");
        frame.setSize(400, 700);
        //frame.pack();
        //frame.setResizable(false); 
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setLayout(new GridLayout(0,1));
        contentPane = new  JPanel();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        frame.add(contentPane);
        label = new JLabel("\n");
        JLabel labe2 = new JLabel("Below are the indexator xml");
        label.setAlignmentY(Component.CENTER_ALIGNMENT);
        //frame.add(label);
        JButton buttonInd = new JButton("Indexate");
        buttonInd.setAlignmentY(Component.CENTER_ALIGNMENT);
        buttonInd.setHorizontalAlignment(JButton.CENTER);
        JButton convertandrender = new JButton(" Render");
        JButton convertandwrite = new JButton("Writeto File");
        textField=new JTextField(20); //  textField=new JTextField("The same");
        JButton search = new JButton("Search"); 
        
        textArea = new JTextArea();  
        textArea.setSize(400,300);    
        textArea.setLineWrap(true);
        textArea.setEditable(true);
        textArea.setVisible(true);
        JScrollPane scroll = new JScrollPane (textArea);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
        contentPane.add(buttonInd);
        contentPane.add(convertandwrite);
        contentPane.add(convertandrender);
        contentPane.add(label);
        contentPane.add(textField);
        contentPane.add(search);
        contentPane.add(labe2);
        contentPane.add(scroll);}
            
      public static void main(String[] args) {
         Jr frame=new Jr();  
      }
    }
    But despite other components are displayed as standart, the textfield
    is like multi-line jtextarea components. No changes to it help.
    What should I do to correct it? What other options can I apply?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    There are several changes to make:
    remove the static from the textfield and textare definitions.
    call setVisble() AFTER all the GUI changes and updates have been been done.
    This compiler warning should be fixed:
    static method should be qualified by type name, JFrame,nstead of by an expression
    Java Code:
        frame.setDefaultLookAndFeelDecorated(true);    
             ^
    With those changes I don't see any problems when the code is compiled and executed.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    What do you mean under:
    frame.setDefaultLookAndFeelDecorated(true); -- it is present in my code.
    I put setVisible() in the end or in main() and nothing changes.
    I also deleted static - and nothing changed, despite I need static as I use this propeties in another methods-- so assigning the text to them, so with craetion of objects it would not be able in another mthods and classes.
    Would you show your version of code?- as the issue is in Big textfiled as Textarea.

  4. #4
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Why I got such big (in vertical size) single-line JtextField in my app?-22233.jpg
    Here is visible big textfield on second image. The first image is blank gray frame.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Try adding the textfield to a JPanel and then adding that to contentPane
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    contentPane is the instance of Jpanel

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    What happened when you tried what I suggested?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Nothing.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Strange. Here's what I get when I did it:
    Attached Thumbnails Attached Thumbnails Why I got such big (in vertical size) single-line JtextField in my app?-tf_prtscrn.png  
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Did your used my original code?
    It really strange that such thing could happed - but I even launched in Ecclipse and this huge texstfield is also there (I usually use Jgrasp), anyway in your screen there is a big gap after Jtextfield. Maybe Jpanel is confined to 4-5 conponents.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Did your used my original code?
    Yes, with the changes I described in post#2 and post#5
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Would you deliver your code here.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Sorry, I don't post much code.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Would you provide the excerpts with your changes?

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    How about you show the code with the changes Norm suggested, as you imply you have made changes with your "nothing" post when asked what happened when you made the changes.

    At least that way we'll see what the differences are.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    I do not know what it means:
    static method should be qualified by type name, JFrame,nstead of by an expression
    Java Code:
    1
    2

    Java Code:
     frame.setDefaultLookAndFeelDecorated(true);
    ^ -by what typenames. I used --
    Java Code:
     frame.setDefaultLookAndFeelDecorated(true);

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    static method should be qualified by type name, JFrame
    static methods should use the name of the class for referencing, not the a reference to the class.
    See the tutorial: Understanding Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    I do know it clearly. But I should create the instances of label, textareas and buttons inside the frame constructor, or should I do it in main().
    I made such changes in constructor- frame.add(contentPane) to this.add(contentPane) and deleted - frame = new JFrame();- as the frame creation is also in main(). But it helped (seems to be) that the frame is filled with the components from the start not blank one.
    But the textfield is huge again. I even composed the frame with the Jpanel and just Jtextfiled inside it the result the same. Even just textfiled inside of Jframe-it is huge again. As just adding the just textfield in main().
    Maybe I need explicitly tell the compiler about the size or bounds of textfield.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Try another layout manager. I've never used BoxLayout. The textfield in post#9 wasn't huge.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    6

    Default Re: Why I got such big (in vertical size) single-line JtextField in my app?

    Should it depend on layout manager? Just the textfiled?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 10-28-2014, 01:31 PM
  2. how to delete single string from JTextField??
    By raffs03 in forum New To Java
    Replies: 2
    Last Post: 07-03-2013, 09:35 AM
  3. JTextField size - gridbaglayout
    By Dex in forum AWT / Swing
    Replies: 2
    Last Post: 12-31-2012, 05:05 AM
  4. Applet JTextField Size Problem
    By a13w in forum New To Java
    Replies: 4
    Last Post: 09-19-2009, 07:52 AM
  5. Merged TIF file size is more larger than the sum of single TIF files
    By subrahmanyam.adapa in forum Advanced Java
    Replies: 3
    Last Post: 01-26-2009, 01:19 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
  •