Java JOptionPanel change text field with TAB


 
Thread Tools Search this Thread
Top Forums Programming Java JOptionPanel change text field with TAB
# 1  
Old 10-24-2014
Java JOptionPanel change text field with TAB

So I don't really know anything about Frames, Windows, or Panels.. I just got interested in Java because a coworker is doing classes in it. I know some other languages but never did GUI things...I literally just got NetBeans, and drew up a dialog using it's Design view.

All I want is for the TAB key to go to the next textfield. What's the simple way?

Code:
package com.neutronscott;
import javax.swing.JOptionPane;
public class hw1 {
    public static void main(String[] args) {
        InputPanel myPanel = new InputPanel();
        JOptionPane.showMessageDialog(null, myPanel);
        System.out.println("Name: " + myPanel.getFirstName() + " " myPanel.getLastName());
    }
    
}

That's all I got. The dialog that it created is a lot. I'll keep it brief:

Code:
package com.neutronscott;

public class InputPanel extends javax.swing.JPanel {

    public InputPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        firstName = new javax.swing.JTextPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        lastName = new javax.swing.JTextPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        age = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        jScrollPane2.setViewportView(firstName);

        jScrollPane3.setViewportView(lastName);

        jScrollPane4.setViewportView(age);

        jLabel1.setText("First Name");

        jLabel2.setText("Last Name");

        jLabel3.setText("Age");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>                        
  
    /**
     *
     * @return the java.lang.String
     */
    public String getFirstName() {
        return this.firstName.getText();
    }
    public String getLastName() {
        return this.lastName.getText();
    }
    public Integer getAge() {
        return Integer.parseInt(this.age.getText());
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JTextPane age;
    private javax.swing.JTextPane firstName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextPane lastName;
    // End of variables declaration                   
}

---------- Post updated 10-24-14 at 12:11 AM ---------- Previous update was 10-23-14 at 10:08 PM ----------

I'm thinking probably because it needs a JFrame around it to inherit all the default focus stuff.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add tab after digit in specific field in file

I am trying to add a tab after the last digit in $3 in the input. The grep below is all I can think off. Thank you :) sed -n 's/:/&/p' input input chr1 955542 955763AGRN-6|gc=75 chr1 957570 957852AGRN-7|gc=61.2 chr1 976034 976270AGRN-9|gc=74.5 desired output chr1... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

How to sort the 6th field of tab delimited files?

Here's a sample of the data: NAME BIRTHDAY SEX LOCATION AGE ID Jim 05/11/1986 M Japan 27 86 Rei 08/25/1990 F Korea 24 33 Jane 02/24/1985 F India 29 78 I've been trying to sort files using the... (8 Replies)
Discussion started by: maihani
8 Replies

3. Shell Programming and Scripting

Substitute newline with tab at designated field separator

Hello, I need to replace newline with tab at certain lines of the file (every four lines is a record). infile.fq: @GAIIX-300 ATAGTCAAAT + _SZS^\\\cd @GAIIX-300 CATACGACAT + hhghfdffhh @GAIIX-300 GACGACGTAT + gggfcfoutfile: @GAIIX-300 ATAGTCAAAT + _SZS^\\\cd @GAIIX-300 ... (6 Replies)
Discussion started by: yifangt
6 Replies

4. Windows & DOS: Issues & Discussions

Change tab size to 4

forum members, gvim version 6.0.150.0 Vi has been my favorite editor for over 30 years. Mostly with Unix but now with windows XP. It works fine but I want to change the tab to 4 spaces instead of 8. I read on the internet that I can edit the .vimrc file but I only have an _vimrc... (12 Replies)
Discussion started by: jerryd
12 Replies

5. UNIX for Dummies Questions & Answers

change field separator only from nth field until NF

Hi ! input: 111|222|333|aaa|bbb|ccc 999|888|777|nnn|kkk 444|666|555|eee|ttt|ooo|ppp With awk, I am trying to change the FS "|" to "; " only from the 4th field until the end (the number of fields vary between records). In order to get: 111|222|333|aaa; bbb; ccc 999|888|777|nnn; kkk... (1 Reply)
Discussion started by: beca123456
1 Replies

6. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

7. UNIX for Dummies Questions & Answers

Insert Field into a tab-delimited file

Hello, I have about 100 files in a directory with fields which are tab delimited. I would like to append the file name as the first field and it has to be done as many times as the total lines in the file. For example, myFile1.txt has the following data: 1 x y z 2 a b ... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

8. Shell Programming and Scripting

insert a field into a tab delimited file

Hello, Can someone help me to do this with awk or sed? I have a file with multiple lines, each line has many fields separated with a tab. I would like to add one more field holding 'na' in between the first and second fields. old file looks like, 1, field1 field2 field3 ... 2, field1... (7 Replies)
Discussion started by: ssshen
7 Replies

9. Shell Programming and Scripting

join - using *only* tab as a field separator

I have files with tabs separating the fields but those fields values can have whitespace characters (basically a text string). I want to instruct join to not consider white spaces as separators but only tabs. I have tried: join -t "<Tab>" file1 file2 join -t "<tab>" file1 file2 join -t "\t"... (7 Replies)
Discussion started by: FrancoisCN
7 Replies

10. UNIX for Dummies Questions & Answers

How do I specify tab as field separator for sort?

I'm trying to use sort on a file with tab-delimited fields. I can't figure out how to tell sort to use the tab character as the field separator. I'm trying this on both an HP Unix system and on OS X (using bash on both). Things I've tried: sort -t\t sort -t"\t" sort -t\"\t\" I've tried... (8 Replies)
Discussion started by: SSteve
8 Replies
Login or Register to Ask a Question