Results 1 to 6 of 6
  1. #1
    VinTiger is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default Text are not visible in GUI

    My text area in this program I'm working on is not visible, only the buttons are....any help appreciated.

    Java Code:
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    
    public class MyText extends JFrame {
    
        private Toolkit toolkit;
    
    
    public static int LineCount = 0; //Counts the lines.
       public static String[] content;  
       
       public static void ReadFile() throws Exception { 
    
          BufferedReader TextFileReader = new BufferedReader(new FileReader("./info.txt")); 
    
          String c;
          String t;
    
          t = "Blank";
          while((c = TextFileReader.readLine()) != null) {  
             LineCount++;
             t += ","+ c;
          }
    
          t = t.replaceAll("Blank,",""); 
          content = new String[LineCount];
          content = t.split(",");
          TextFileReader.close(); 
          
          
          for(int i = 0; i < 7; i++)  //Keep printing as long as i is smaller than 7, which is what I need for my text file.
              System.out.println(content[i]); //prints the first part of my list of names.
             
       }
    
    
        public MyText() {
    
            setTitle("Name and Address");
            setSize(300, 400);
    
            toolkit = getToolkit();
            Dimension size = toolkit.getScreenSize();
            setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
    
            JPanel panel = new JPanel();
            getContentPane().add(panel);
    
    	panel.setLayout(null);
    
    
            JButton beep = new JButton("Next");
            beep.setBounds(150, 60, 80, 30);
            beep.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    toolkit.beep();
    for(int i = 0; i > 0; i++)
    System.out.println(content[i]);
    
    
                }
            });
    
           JButton close = new JButton("Back");
           close.setBounds(50, 60, 80, 30);
           close.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent event) {
                   toolkit.beep();
    
    for(int i = 0; i > 0; i--)
    System.out.println(content[i]);
    
              }
           });
    
            panel.add(beep);
            panel.add(close);
    
        }
    
        public static void main(String[] args) {
    
            MyText buttons = new MyText();
            buttons.setVisible(true);
    
        }
    }

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    You have no text that should be displayed in the GUI. Use JLabels and/or JTextAreas to display text in a GUI.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    JTextArea is much better. So in future you can do any formatting and processing easily than the button.

    First of all you have to add all the components in the panel. So you may want to look at the layouts as well.

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    I think that JLabel may actually work better if you don't need the text to be user-editable. JTextAreas do not allow text alignment and are actually have very little in the way of formatting capabilities. If you use a JLabel you can just use html new-line tags. (Both <br> and <p> create new lines, but I believe you would use <br> to force new line, and <p> for possible new line.)

    My take on it is that unless you need user-editable text, use a JLabel as it allows text alignment.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Or else, you can use setEditable(false) to disable the content edit on the JTextArea. Still you can copy the content and selectable, but cannot change the content.

Similar Threads

  1. Tab or Table not visible
    By madhuvanthi2312 in forum SWT / JFace
    Replies: 1
    Last Post: 04-25-2009, 09:00 AM
  2. only ~200x200px Applet area visible
    By jumper19 in forum New To Java
    Replies: 8
    Last Post: 02-02-2009, 03:05 AM
  3. Address bar not visible
    By Akashchopra521 in forum New To Java
    Replies: 0
    Last Post: 12-03-2008, 07:13 AM
  4. constructor ... is not visible
    By emceenugget in forum New To Java
    Replies: 2
    Last Post: 09-27-2008, 05:12 AM
  5. How do you keep multiple popups visible?
    By Jacob Abernathy in forum New To Java
    Replies: 6
    Last Post: 09-15-2008, 06:35 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
  •