2008년 6월 22일 일요일

swing jTextPane.select() 메서드 관련


import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;


public class SelectTest extends JFrame {

private JPanel jContentPane = null;
private JButton jButton = null;
private JScrollPane jScrollPane = null;
private JTextPane jTextPane = null;

public SelectTest() {
super();
initialize();

}

private void initialize() {
this.setSize(new Dimension(387, 282));
this.setContentPane(getJContentPane());
this.setTitle("SelectTest");
}

private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}

private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(131, 15, 113, 30));
jButton.setText("select");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
jTextPane.grabFocus();//이부분 추가하세요 ^^!
//문제의 select() 메서드....
jTextPane.select(0,10);



//버튼을 클릭했을때의 텍스트팬의 선택된구역의 좌표
System.out.println(jTextPane.getSelectionStart()+""+jTextPane.getSelectionEnd());



}catch(Exception ee) {}

}
});
}
return jButton;
}

private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(43, 74, 300, 155));
jScrollPane.setViewportView(getJTextPane());
}
return jScrollPane;
}

private JTextPane getJTextPane() {
if (jTextPane == null) {
jTextPane = new JTextPane();
}
return jTextPane;
}

public static void main(String[] args) {
SelectTest ss = new SelectTest();
ss.setVisible(true);

}


}

댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby