import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Insets;
import javax.swing.JTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.EventObject;
import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;public class NewJFrame21 extends javax.swing.JFrame { /** Creates new form NewJFrame21 */
public NewJFrame21() {
initComponents();
} @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); AbstractAction moveForward = new AbstractAction() { public void actionPerformed(ActionEvent e) {
int rowCount = jTable1.getRowCount();
int colCount = jTable1.getColumnCount(); int selRow = jTable1.getSelectedRow();
int selCol = jTable1.getSelectedColumn();
int yingdonggeshu = 0; do {
yingdonggeshu = yingdonggeshu + 1;
if (selCol == colCount - 1) {
if (selRow == rowCount - 1) {
selCol = -1;
selRow = 0;
} else {
selCol = -1;
selRow++;
}
}
} while ((jTable1.getModel().isCellEditable(selRow, selCol + yingdonggeshu)) == false); jTable1.changeSelection(selRow, selCol + yingdonggeshu, false, false);
jTable1.editCellAt(selRow, selCol + yingdonggeshu); }
};
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null}
},
new String[]{
"能编辑1", "Title 2", "能编辑3", "标题 4", "标题 5", "标题 6", "标题 15", "标题 18", "能编辑"
}) { boolean[] canEdit = new boolean[]{
true, false, true, false, false, true, false, false, true
}; public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
jTable1.setColumnSelectionAllowed(true);
jTable1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "moveForward");
jTable1.getActionMap().put("moveForward", moveForward); FilePathCellEditor f1 = new FilePathCellEditor();
TableColumn sportColumn = jTable1.getColumnModel().getColumn(0);
//System.out.print(sportColumn) sportColumn.setCellEditor(f1);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable1.getColumnModel().getColumn(0).setResizable(false);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(2).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE).addGap(314, 314, 314)));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE).addGap(25, 25, 25))); pack();
}// </editor-fold> public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new NewJFrame21().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}class FilePathCellEditor extends AbstractCellEditor implements TableCellEditor { JPanel panel = new JPanel(new BorderLayout());
JTextField tf = new JTextField();
JButton btn = new JButton("...");
JFileChooser fileChooser = null; public FilePathCellEditor() {
panel.add(tf, BorderLayout.CENTER);
panel.add(btn, BorderLayout.EAST);
tf.grabFocus(); btn.setMargin(new Insets(0, 0, 0, 0));
btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
if (fileChooser == null) {
fileChooser = new JFileChooser();
}
int r = fileChooser.showOpenDialog(panel);
if (r == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
tf.setText(file.getPath());
}
}
});
tf.setBorder(null);
} public boolean isCellEditable(EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
return ((MouseEvent) anEvent).getClickCount() >= 2;
}
return true;
} public Object getCellEditorValue() {
return tf.getText();
} public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, int row, int column) { tf.setText(value == null ? "" : value.toString()); return panel;
}
}
问题之1 jtable 在第一列 加入 FilePathCellEditor 单元格编辑器后,焦点的控制顺序就被打乱了(原来用enter跳到同排下一个可编辑的单元格,选择文件路径后enter就直接跳到同列的下面一个单元格,(理想的顺序是不用鼠标移动的效果)。请问 2 我如何通过 jtable.getColumnClass 取得单元格编辑器 FilePathCellEditor 实例 jtable.getColumnClass.getColumn(0)取得的总是 java.lang.class 无法转换为FilePathCellEditor
我 取得单元格编辑器 FilePathCellEditor 实例 后 主要目的是让里边的 JTextField 获得焦点,达到直接快速录入数据
(不用鼠标点一下)的目的。 如果大家有啥更好的方法 ,请赐教!!
import java.awt.Component;
import java.awt.Insets;
import javax.swing.JTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.EventObject;
import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;public class NewJFrame21 extends javax.swing.JFrame { /** Creates new form NewJFrame21 */
public NewJFrame21() {
initComponents();
} @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); AbstractAction moveForward = new AbstractAction() { public void actionPerformed(ActionEvent e) {
int rowCount = jTable1.getRowCount();
int colCount = jTable1.getColumnCount(); int selRow = jTable1.getSelectedRow();
int selCol = jTable1.getSelectedColumn();
int yingdonggeshu = 0; do {
yingdonggeshu = yingdonggeshu + 1;
if (selCol == colCount - 1) {
if (selRow == rowCount - 1) {
selCol = -1;
selRow = 0;
} else {
selCol = -1;
selRow++;
}
}
} while ((jTable1.getModel().isCellEditable(selRow, selCol + yingdonggeshu)) == false); jTable1.changeSelection(selRow, selCol + yingdonggeshu, false, false);
jTable1.editCellAt(selRow, selCol + yingdonggeshu); }
};
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null}
},
new String[]{
"能编辑1", "Title 2", "能编辑3", "标题 4", "标题 5", "标题 6", "标题 15", "标题 18", "能编辑"
}) { boolean[] canEdit = new boolean[]{
true, false, true, false, false, true, false, false, true
}; public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
jTable1.setColumnSelectionAllowed(true);
jTable1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "moveForward");
jTable1.getActionMap().put("moveForward", moveForward); FilePathCellEditor f1 = new FilePathCellEditor();
TableColumn sportColumn = jTable1.getColumnModel().getColumn(0);
//System.out.print(sportColumn) sportColumn.setCellEditor(f1);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable1.getColumnModel().getColumn(0).setResizable(false);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(2).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE).addGap(314, 314, 314)));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE).addGap(25, 25, 25))); pack();
}// </editor-fold> public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new NewJFrame21().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}class FilePathCellEditor extends AbstractCellEditor implements TableCellEditor { JPanel panel = new JPanel(new BorderLayout());
JTextField tf = new JTextField();
JButton btn = new JButton("...");
JFileChooser fileChooser = null; public FilePathCellEditor() {
panel.add(tf, BorderLayout.CENTER);
panel.add(btn, BorderLayout.EAST);
tf.grabFocus(); btn.setMargin(new Insets(0, 0, 0, 0));
btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
if (fileChooser == null) {
fileChooser = new JFileChooser();
}
int r = fileChooser.showOpenDialog(panel);
if (r == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
tf.setText(file.getPath());
}
}
});
tf.setBorder(null);
} public boolean isCellEditable(EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
return ((MouseEvent) anEvent).getClickCount() >= 2;
}
return true;
} public Object getCellEditorValue() {
return tf.getText();
} public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, int row, int column) { tf.setText(value == null ? "" : value.toString()); return panel;
}
}
问题之1 jtable 在第一列 加入 FilePathCellEditor 单元格编辑器后,焦点的控制顺序就被打乱了(原来用enter跳到同排下一个可编辑的单元格,选择文件路径后enter就直接跳到同列的下面一个单元格,(理想的顺序是不用鼠标移动的效果)。请问 2 我如何通过 jtable.getColumnClass 取得单元格编辑器 FilePathCellEditor 实例 jtable.getColumnClass.getColumn(0)取得的总是 java.lang.class 无法转换为FilePathCellEditor
我 取得单元格编辑器 FilePathCellEditor 实例 后 主要目的是让里边的 JTextField 获得焦点,达到直接快速录入数据
(不用鼠标点一下)的目的。 如果大家有啥更好的方法 ,请赐教!!
记得我在回你上个帖子的时候,说过,还有好多事情要做,有更多的事情可做吗?
呵呵~~首先提出几点个人建议,你的这个table,完全可以单独封装起来。
作为一个单独的控件。这样有很多好处,包括写代码的时候,好多东西也非常方便。
你现在这样,说实话,看起来非常的零散,而且,你也知道程序应该尽可能的高内聚。你这里却如同东北的一道名菜:乱炖。当然也许只是一个演示, 所以你没有细加区分。唉,今天……太阳很足,我被太阳从右前方直射,眼睛都睁不开~~
我知道你要的东西……
嗯,如果你请我吃一顿大餐,我就告诉你~~哈啊哈
今后的网络是越来越快的,给swing 发展奠定了希望,当然,也许以后 swing靠javafx 第n代翻身现在打点基础,以后等机会来吧。 退一万步 swing没有钱途,但从中体会 一下sun技术人员的那些程序设计开发思维的理念是很有好处的。 对于一个编程自学者来讲,困难是重重的,但求积少成多,不求速成。不要被程序所累 。 希望大家爱好swing的多多交流
swing中可以说体现了许多优良的设计模式和思想。
我从大学毕业,就开始接触swing。那时候还是1.4,5.0没有发布的时候。这些年,我虽然也在读swing的源码,但是,多知道一点就会发现自己所知,不过是冰山一角……不过……这好像跟请我吃大餐没多少关系啊~~~真是,只要答应就行了,又没有说真要你请~~
罢了,swing同道真是不多。我欣赏swing构架的灵活,可以说,读过不少的代码,包括源码之后,我感觉swing的思想是有魅力的,加上java代码严谨的结构,构成的是一种有韵律的节奏感和美感,就像一只剥了皮的鸡蛋,闪着诱人的光芒……呵呵
代码贴给你。我做了些修改,你自己多家体会。如果你愿意,我们可以多交流。看你关于这个问题,三个帖子了,说实话,男的一个执着的人,你是工作还是学生?
先把代码给你。一些细节,你若知道就很简单,否则,会让你迷惑很长时间的。
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Insets;
import javax.swing.JTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.EventObject;
import javax.swing.AbstractAction;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;public class NewJFrame21 extends javax.swing.JFrame { /** Creates new form NewJFrame21 */
public NewJFrame21() {
initComponents();
} // @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable() { private KeyListener ketListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
e.setSource(jTable1);
jTable1.dispatchEvent(e);
}
}
}; }; setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); AbstractAction moveForward = new AbstractAction() { public void actionPerformed(ActionEvent e) {
int rowCount = jTable1.getRowCount();
int colCount = jTable1.getColumnCount(); int selRow = jTable1.getSelectedRow();
int selCol = jTable1.getSelectedColumn();
int yingdonggeshu = 0; do {
yingdonggeshu = yingdonggeshu + 1;
if (selCol == colCount - 1) {
if (selRow == rowCount - 1) {
selCol = -1;
selRow = 0;
} else {
selCol = -1;
selRow++;
}
}
} while ((jTable1.getModel().isCellEditable(selRow, selCol
+ yingdonggeshu)) == false); jTable1.changeSelection(selRow, selCol + yingdonggeshu, false,
false);
jTable1.editCellAt(selRow, selCol + yingdonggeshu); }
};
jTable1
.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
{ null, null, null, null, null, null, null,
null, null },
{ null, null, null, null, null, null, null,
null, null },
{ null, null, null, null, null, null, null,
null, null } }, new String[] { "能编辑1",
"Title 2", "能编辑3", "标题 4", "标题 5", "标题 6",
"标题 15", "标题 18", "能编辑" }) { boolean[] canEdit = new boolean[] { true, false, true,
false, false, true, false, false, true }; public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
jTable1.setColumnSelectionAllowed(true);
jTable1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
"moveForward");
jTable1.getActionMap().put("moveForward", moveForward); FilePathCellEditor f1 = new FilePathCellEditor();
TableColumn sportColumn = jTable1.getColumnModel().getColumn(0);
// System.out.print(sportColumn) sportColumn.setCellEditor(f1);
jScrollPane1.setViewportView(jTable1);
jTable1.getColumnModel().getSelectionModel().setSelectionMode(
javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jTable1.getColumnModel().getColumn(0).setResizable(false);
jTable1.getColumnModel().getColumn(1).setResizable(false);
jTable1.getColumnModel().getColumn(2).setResizable(false);
jTable1.getColumnModel().getColumn(3).setResizable(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addContainerGap().addComponent(
jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
452, Short.MAX_VALUE).addGap(314, 314, 314)));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 275,
Short.MAX_VALUE).addGap(25, 25, 25))); pack();
}// </editor-fold> public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new NewJFrame21().setVisible(true);
}
});
} // Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}class FilePathCellEditor extends AbstractCellEditor implements TableCellEditor { JPanel panel = new JPanel(new BorderLayout());
JTextField tf = new JTextField();
JButton btn = new JButton("...");
JFileChooser fileChooser = null; private KeyListener l = null; public FilePathCellEditor() {
panel.add(tf, BorderLayout.CENTER);
panel.add(btn, BorderLayout.EAST);
tf.grabFocus(); btn.setMargin(new Insets(0, 0, 0, 0)); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
if (fileChooser == null) {
fileChooser = new JFileChooser();
}
int r = fileChooser.showOpenDialog(panel);
if (r == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
tf.setText(file.getPath());
}
}
});
tf.setBorder(null);
} public boolean isCellEditable(EventObject anEvent) {
if (anEvent instanceof MouseEvent) {
return ((MouseEvent) anEvent).getClickCount() >= 2;
}
return true;
} public Object getCellEditorValue() {
return tf.getText();
} public Component getTableCellEditorComponent(final JTable table,
Object value, boolean isSelected, int row, int column) { tf.setText(value == null ? "" : value.toString()); KeyAdapter l = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
e.setSource(table);
table.dispatchEvent(e);
}
}
};
btn.addKeyListener(l);
this.l = l;
return panel;
} @Override
public boolean stopCellEditing() {
if (l != null) {
btn.removeKeyListener(l);
l = null;
}
return super.stopCellEditing();
}
}
我毕业的时候……5.0发布了……唉,
那,假设说我给你出一个问题,你用的一个面板,我要求如果编辑时如果是文本框,里面有文字的话则全部选中。编辑的时候焦点默认定在textfield里面,可以直接输入文字,请你尝试。当然,以你现在的代码结构可能还比较麻烦呢~~呵呵。
* To change this template, choose Tools | Templates
* and open the template in the editor.
*//*
* NewJFrame.java
*
* Created on 2009-12-21, 20:12:18
*/package javaapplication2;/**
*
* @author Administrator
*/
public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */
public NewJFrame() {
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() { jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setLayout(new java.awt.BorderLayout()); jTextField1.setText("代码乱 还要请暗淡星辰老弟 化乱为治哦");
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jTextField1FocusGained(evt);
}
}); jRadioButton1.setText("切换焦点来看效果"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(204, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(110, 110, 110))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)))
.addGap(86, 86, 86))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(116, 116, 116)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(62, 62, 62)
.addComponent(jRadioButton1)
.addContainerGap(72, Short.MAX_VALUE))
); pack();
}// </editor-fold> private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {
if(jTextField1.getText()==null){}
else{jTextField1.selectAll();}
} /**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
} // Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JTextField jTextField1;
// End of variables declaration}
我用netbean 画的哦, 看是不是您要的效果