Thread: Java GUI text boxes and user input

Results 1 to 1 of 1
  1. #1 Java GUI text boxes and user input 
    Registered Member
    Join Date
    Jul 2009
    Posts
    89
    Thanks given
    2
    Thanks received
    0
    Rep Power
    1
    EDIT:: PROBLEM SOLVED DISCOVERED JTEXTAREA

    Hello all,

    I am new to creating a GUI. What I'm trying to do is this


    Here's what I have so far of the GUI


    Code:
    /**
     * 
     */
    package gui;
    
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    import reverseMain.ReverseRun;
    
    /**
     * 
     *
     */
    
    public class ReverseTextGUI extends ReverseRun implements ActionListener {
    	
    	public static JFrame frame;
    	
        private JPanel northFlowLayoutPanel;
        private JPanel centerFlowLayoutPanel;
        private JPanel southFlowLayoutPanel;
        
        private final JButton reverse = new JButton("Reverse");
        private final JTextField userInput = new JTextField(50);
        private final JTextField reverseOutput = new JTextField(50);
    
    	public void actionPerformed(ActionEvent e) {
    		
    		reverse.addActionListener((ActionListener) reverse);
    		reverse.setActionCommand("Reverse");
    		
    		if ("algorithm".equals(e.getActionCommand())) {
    			System.out.println("test");
    		}
    
    	}
    	
    	public void initUI() {
    
    		northFlowLayoutPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            northFlowLayoutPanel.add(userInput);
            userInput.setPreferredSize(new Dimension(150,100));
            
            centerFlowLayoutPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            centerFlowLayoutPanel.add(reverse);
            
            southFlowLayoutPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            southFlowLayoutPanel.setBorder(BorderFactory.createTitledBorder("Output text"));
            southFlowLayoutPanel.add(reverseOutput);
            reverseOutput.setPreferredSize(new Dimension(150,100));
            
            JFrame frame = new JFrame("Backwardizer");
            frame.setLayout(new BorderLayout());      // This is the default layout
            frame.add(northFlowLayoutPanel, BorderLayout.PAGE_START);
            frame.add(centerFlowLayoutPanel, BorderLayout.CENTER);
            frame.add(southFlowLayoutPanel, BorderLayout.PAGE_END);
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.setSize(750, 500);
    
    	}
    }
    What I'm having trouble doing is:
    • Getting the button to align exactly how I want
    • Getting the cursor to start at the top left corner of the textfield
    • getting the input/output to use more than one line of the box


    I think I can figure out the action listeners and commands to get the button to work and use the input/output text fields, but I'm just having a really hard time getting it to look the way I want it to.

    I'm wondering if JTextFields aren't the best way to go at this.
    Any ideas?
    Last edited by Krastallas; 08-10-2015 at 12:14 AM. Reason: answered question
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 1
    Last Post: 05-21-2013, 03:46 AM
  2. Replies: 23
    Last Post: 05-23-2012, 11:53 AM
  3. Replies: 4
    Last Post: 01-14-2012, 12:05 AM
  4. Replies: 9
    Last Post: 12-12-2010, 03:13 AM
  5. Replies: 2
    Last Post: 03-20-2009, 03:58 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •