日期:2014-05-20 浏览次数:20690 次
java.awt.EventQueue.invokeLater(new java.lang.Runnable(){ @Override public void run(){ JFrame frame = new JFrame("Java Rocks"); final JTextArea textinput = new JTextArea(8,10); JScrollPane scroller = new JScrollPane(textinput); textinput.addKeyListener(new KeyAdapter(){ @Override public void keyPressed(KeyEvent e){ if (textinput.getText().trim().isEmpty() && e.getKeyCode() == KeyEvent.VK_ENTER) { e.consume(); } } }); frame.getContentPane().add(scroller); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } });