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 4 of 4

Thread: JTextArea display button

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default JTextArea display button

    Hello there
    i'm trying to make a button where i push that and it display what is in the text file on the JTextArea, but i can't not make it to work when i press the button i have no idea how to make it work. I can make it display the file when i write in where it is supose to be but i would like to choose from what file it is suppose to show
    Here is my code so far:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;  
     
    public class login implements ActionListener {
    	public void actionPerformed(ActionEvent event) {
    		JFrame frame2 = new JFrame();
    		frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame2.setSize(new Dimension(600, 300));
    		frame2.setLocation(new Point(300, 300));
    		frame2.setLayout(new BorderLayout());
    		frame2.setTitle("Home");;
    		//buttons
    		JButton overforPenge = new JButton();
    		overforPenge.setText("Overfør penge");
    		JButton konti1 = new JButton();
    		overforPenge.setText("Brugs konti");
    		JButton konti2 = new JButton();
    		overforPenge.setText("Opsparing");
     
    		//north
    		JPanel North = new JPanel(new GridLayout(1,3));
    		North.add(new JLabel(""));
    		North.add(new JLabel("CAC Bank"));
    		North.add(new JLabel(""));
     
     
    		// venstre række
    		JPanel West = new JPanel(new GridLayout(4,1));
    		West.add(new JButton("Se konti"));
    		West.add(overforPenge);
    		West.add(new JButton("Indtast løn"));
    		West.add(new JButton("Indtast udgifter"));
    		overforPenge.addActionListener(new Overfor());
     
    		//Center
    		JTextArea Center = new JTextArea(400, 500);
    		try{Center.read(new FileReader("logfile1.txt"),null);}catch(IOException ioe){}  
     
    		//East
    		JPanel East = new JPanel(new GridLayout(8,2));
    		East.add(konti1);
    		East.add(new JLabel("Tilrådighed"));
    		East.add(konti2);
    		East.add(new JLabel("Tilrådighed"));
    		East.add(new JButton("Konti"));
    		East.add(new JLabel("Tilrådighed"));
    		East.add(new JButton("Konti"));
    		East.add(new JLabel("Tilrådighed"));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
    		East.add(new JLabel(""));
     
     
     
    		//South
    		JPanel South = new JPanel (new GridLayout(1,3));
    		South.add(new JLabel(" "));
    		South.add(new JLabel(" "));
    		South.add(new JButton("Log out"));
     
     
    		//layout
    		frame2.add(North, BorderLayout.NORTH);
    		frame2.add(West, BorderLayout.WEST);
    		frame2.add(Center, BorderLayout.CENTER);
    		frame2.add(East, BorderLayout.EAST);
    		frame2.add(South, BorderLayout.SOUTH);
     
     
    		frame2.setVisible(true);
    	}
     
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,324
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: JTextArea display button

    Sounds like a job for a JFileChooser.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: JTextArea display button

    Quote Originally Posted by KevinWorkman View Post
    Sounds like a job for a JFileChooser.
    Thanks for the reply now i have been trying to make sense of it with that but with no luck :s
    I have a Jframe and in that i have a JTextArea and two buttons and when i press one button it displays on txt file in the JTextArea and another if i press the other button. it is possible i could get an example of how you do that?
    because i'm pretty lost :s

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,324
    My Mood
    Hungover
    Thanks
    142
    Thanked 624 Times in 535 Posts

    Default Re: JTextArea display button

    How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help with image display on JTextArea
    By mozart66 in forum AWT / Java Swing
    Replies: 4
    Last Post: May 18th, 2012, 09:35 AM
  2. Radio button .. display empty screen ?? plz Help
    By smasm in forum AWT / Java Swing
    Replies: 4
    Last Post: April 7th, 2012, 07:21 PM
  3. Trying to display text from file in JTextArea. Please Help.
    By rjdelight in forum Java Theory & Questions
    Replies: 7
    Last Post: June 29th, 2011, 05:10 AM
  4. How to display a button with an image on it?
    By ice in forum AWT / Java Swing
    Replies: 10
    Last Post: November 13th, 2010, 05:20 AM
  5. program a button that copy whatever in a JTextArea
    By voltaire in forum AWT / Java Swing
    Replies: 5
    Last Post: May 17th, 2010, 12:43 AM