JTextField, JTextArea¿¡¼­ ÇÑ±Û ÀÔ·Â ¹æ¹ý


[ Follow Ups ] [ Post Followup ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

Posted by ±è´öÅ on November 29, 1997 at 17:57:39:

In Reply to: ½ºÀ®¿¡¼­ ÇѱÛÀÔ·Â... posted by Çϵ¿¿í on November 26, 1997 at 11:58:54:


±×·¸°Ô ÇÒ ¼öµµ ÀÖ°ÚÁö¸¸ ´ÙÀ½°ú °°ÀÌ Çϸé .dll È­ÀÏÀ» ¹Ù²ÙÁö ¾Ê°í
JTextField, JTextArea ½ºÀ® ÄÄÆ÷³ÍÆ®¿¡¼­ ÇѱÛÀ» ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù.
JDK 1.1.4 À©µµ¿ìÁî ¹öÀüÀÇ TextField¿Í TextArea ÄÄÆ÷³ÍÆ®°¡
ÇÑ±Û Å° À̺¥Æ®¸¦ ¹ß»ý½ÃÅ°´Â Ư¼ºÀ» ÀÀ¿ëÇÑ °ÍÀÔ´Ï´Ù.
(¼Ö¶ó¸®½º ¹öÀü¿¡¼­´Â ÇÑ±Û Å° À̺¥Æ®¸¦ ¹ß»ý½ÃÅ°Áö ¾Ê±â ¶§¹®¿¡ ¾ÈµÇ´õ±º¿ä.)


´ÙÀ½ È­ÀÏ¿¡ Æ÷ÇԵǴ »õ·Î Á¤ÀÇµÈ Å¬·¡½º JTextField¿Í JTextArea´Â
±âÁ¸ÀÇ ½ºÀ® Ŭ·¡½º JTextField¿Í JTextArea¸¦ °°Àº Ŭ·¡½º À̸§À» °®´Â
´Ù¸¥ Ŭ·¡½º Á¤ÀÇ·Î ´ëÄ¡ÇÏ¿© ÇÑ±Û ÀÔ·ÂÀÌ µÇµµ·Ï ÇÑ °ÍÀÔ´Ï´Ù.


ÀÌ ÇÁ·Î±×·¥À» JTextField³ª JTextArea¸¦ »ç¿ëÇÏ´Â ÇÁ·Î±×·¥ÀÌ
ÀÖ´Â µð·ºÅ丮¿¡ ÄÄÆÄÀÏ Çسõ°Å³ª ÇØ´ç ¿ø½Ã È­ÀÏ¿¡ Æ÷ÇÔ½ÃŲÈÄ,
´Ù½Ã ÄÄÆÄÀÏÇÏ¸é ±âÁ¸ ¼Ò½º ÄÚµåÀÇ ¼öÁ¤¾øÀÌ ÇѱÛÀ» ÀÔ·ÂÇÒ ¼ö ÀÖ½À´Ï´Ù.


½ÇÇà ÀýÂ÷:


C:\example\swing> set CLASSPATH=.;C:\swing-0.5.1\swing.jar
C:\example\swing> javac JTextNativeInputTest.java
C:\example\swing> java JTextNativeInputTest



Notepad.javaÀÇ ½ÇÇà ÀýÂ÷:


C:\swing-0.5.1\examples\Notepad> set CLASSPATH=.;C:\swing-0.5.1\swing.jar
(JTextNativeInputTest.java¸¦ ÀÌ°÷À¸·Î º¹»ç...)
C:\swing-0.5.1\examples\Notepad> javac JTextNativeInputTest.java
(Notepad.java¿¡¼­ ÇѱÛÀÌ Ãâ·ÂµÉ ¼ö ÀÖµµ·Ï
´ÙÀ½°ú °°ÀÌ ¼öÁ¤ÇÑ´Ù.
// editor.setFont(new Font("Courier", Font.PLAIN, 12));
// ===>
editor.setFont(new Font("Monospaced", Font.PLAIN, 12));
)
C:\swing-0.5.1\examples\Notepad> javac Notepad.java
C:\swing-0.5.1\examples\Notepad> java Notepad



====================== JTextNativeInputTest.java ===================


import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;


class JTextField extends com.sun.java.swing.JTextField
{
public JTextField()
{ addFocusListener( focusHandler );
input.addFocusListener( inputFocusHandler );
input.addKeyListener( inputKeyHandler );
add( input );
}


TextField input = new TextField()
{ // TextField°¡ º¸ÀÌÁö ¾Êµµ·Ï Å©±â¸¦ 0À¸·Î ¸¸µç´Ù.
public Dimension getPreferredSize()
{ return new Dimension(0,0);
}
public Dimension getMaximumSize()
{ return new Dimension(0,0);
}
};


FocusListener focusHandler = new FocusAdapter()
{ public void focusGained( FocusEvent ev )
{ input.requestFocus(); // Æ÷Ä¿½º¸¦ TextField·Î Àü¼Û
}
};


FocusListener inputFocusHandler = new FocusListener()
{ public void focusGained( FocusEvent ev )
{ getCaret().setVisible( true ); // ij·µÀÌ °è¼Ó º¸ÀÌ°Ô ÇÑ´Ù.
}
public void focusLost( FocusEvent ev )
{ getCaret().setVisible( false ); // ij·µÀÌ º¸ÀÌÁö ¾Ê°Ô ÇÑ´Ù.
}
};


// TextField¿¡¼­ ¹ß»ýÇÑ Å° À̺¥Æ®¸¦ °¡Á®¿Â´Ù.
KeyListener inputKeyHandler = new KeyListener()
{ public void keyPressed( KeyEvent ev )
{ dispatchEvent( ev );
}
public void keyTyped( KeyEvent ev )
{ input.setText("");
dispatchEvent( ev );
}
public void keyReleased( KeyEvent ev )
{ dispatchEvent( ev );
}
};
}



class JTextArea extends com.sun.java.swing.JTextArea
{
public JTextArea()
{ addFocusListener( focusHandler );
input.addFocusListener( inputFocusHandler );
input.addKeyListener( inputKeyHandler );
add( input );
}


TextArea input = new TextArea()
{ // TextArea°¡ º¸ÀÌÁö ¾Êµµ·Ï Å©±â¸¦ 0À¸·Î ¸¸µç´Ù.
public Dimension getPreferredSize()
{ return new Dimension(0,0);
}
public Dimension getMaximumSize()
{ return new Dimension(0,0);
}
};


FocusListener focusHandler = new FocusAdapter()
{ public void focusGained( FocusEvent ev )
{ input.requestFocus(); // Æ÷Ä¿½º¸¦ TextArea·Î Àü¼Û
}
};


FocusListener inputFocusHandler = new FocusListener()
{ public void focusGained( FocusEvent ev )
{ getCaret().setVisible( true ); // ij·µÀÌ °è¼Ó º¸ÀÌ°Ô ÇÑ´Ù.
}
public void focusLost( FocusEvent ev )
{ getCaret().setVisible( false ); // ij·µÀÌ º¸ÀÌÁö ¾Ê°Ô ÇÑ´Ù.
}
};


// TextArea¿¡¼­ ¹ß»ýÇÑ Å° À̺¥Æ®¸¦ °¡Á®¿Â´Ù.
KeyListener inputKeyHandler = new KeyListener()
{ public void keyPressed( KeyEvent ev )
{ dispatchEvent( ev );
}
public void keyTyped( KeyEvent ev )
{ input.setText("");
dispatchEvent( ev );
}
public void keyReleased( KeyEvent ev )
{ dispatchEvent( ev );
}
};
}


class JTextNativeInputTest
{
public static void main( String[] args )
{
JFrame f = new JFrame();
f.getContentPane().setLayout( new BorderLayout() );


JTextField tf = new JTextField();
f.getContentPane().add( tf, "North" );


JScrollPane scroller = new JScrollPane();
scroller.setBorder( BorderFactory.createLoweredBevelBorder() );
JTextArea ta = new JTextArea();
scroller.setViewportView( ta );


f.getContentPane().add( scroller, "Center" );
f.setSize(200, 300);
f.setVisible( true );
}
}


--
Deogtae Kim (±è´öÅÂ)
CA Lab. CS Dept. KAIST
http://calab.kaist.ac.kr/~dtkim





Follow Ups:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ Follow Ups ] [ Post Followup ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]