jxtableとrxtableを組み合わせます
質問
問題
の機能が欲しいです jxtable の「すべての編集」の動作で rxtable. 。単純なオーバーライドを行うことは問題ありませんが、Rxtableのダブルクリック関数はJxtableで動作しません。ボタンアクションモードを使用する場合は問題ありませんが、F2またはjxtableでrxtableで衝突してダブルクリックして、選択を削除してデフォルトの動作が残ります。それは、それが内部で使用するのは生成されたもののためですか、それとも何か他のものですか?
jxtableをF2ですべて選択するか、ダブルクリック編集するにはどうすればよいですか?
編集:これは、モデルに型整数の列が定義されている場合にのみ発生するようです。文字列またはオブジェクト列に対して定義されているときに期待どおりに機能します。
解決
Kleopatraの修正のおかげで、SelectAllメソッドを変更することができたので、JFormattedTextFieldsと編集のすべてのケースを処理しました。元のコードは編集のためにタイプで機能したため、他のケースに修正を使用しました。これが私が終わったものです。
rxtableのselectallを次のものに置き換えます。
/*
* Select the text when editing on a text related cell is started
*/
private void selectAll(EventObject e)
{
final Component editor = getEditorComponent();
if (editor == null
|| ! (editor instanceof JTextComponent
|| editor instanceof JFormattedTextField))
return;
if (e == null)
{
((JTextComponent)editor).selectAll();
return;
}
// Typing in the cell was used to activate the editor
if (e instanceof KeyEvent && isSelectAllForKeyEvent)
{
((JTextComponent)editor).selectAll();
return;
}
// If the cell we are dealing with is a JFormattedTextField
// force to commit, and invoke selectall
if (editor instanceof JFormattedTextField) {
invokeSelectAll((JFormattedTextField)editor);
return;
}
// F2 was used to activate the editor
if (e instanceof ActionEvent && isSelectAllForActionEvent)
{
((JTextComponent)editor).selectAll();
return;
}
// A mouse click was used to activate the editor.
// Generally this is a double click and the second mouse click is
// passed to the editor which would remove the text selection unless
// we use the invokeLater()
if (e instanceof MouseEvent && isSelectAllForMouseEvent)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
((JTextComponent)editor).selectAll();
}
});
}
}
private void invokeSelectAll(final JFormattedTextField editor) {
// old trick: force to commit, and invoke selectall
editor.setText(editor.getText());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
editor.selectAll();
}
});
}
解決
3つの選択タイプのうち2つで動作するクイックハック
// in selectAll(EventObject) special case the formatted early
if (editor instanceof JFormattedTextField) {
invokeSelectAll(editor);
return;
}
private void invokeSelectAll(final JFormattedTextField editor) {
// old trick: force to commit, and invoke selectall
editor.setText(editor.getText());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
editor.selectAll();
}
});
}
トリックを思い出しました jformattedTextfieldがフォーカスを取得したときにすべてのテキストを選択する方法は? -Typingで編集を開始するときにケースを処理しません。この場合、コンテンツは削除されません(通常のテキストフィールドの場合)が、新しいキーが追加されます。
所属していません StackOverflow