【发布时间】:2015-01-05 16:54:59
【问题描述】:
我自定义了JTable 单元格编辑器,以便允许从JDialog 框架输入数据。为此我使用了一个可编辑的组合框,我为组合框添加了一个ActionListener 以显示对话框。
我的JDialog 可见,但我想让它不可移动,因此用户无法移动它。
这是我目前的代码,
package VIEW;
import VIEW.statManager.SearchProduitEvent;
import VIEW.statManager.SearchProduitEventListener;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.table.TableCellEditor;
import javax.swing.text.JTextComponent;
public class ProduitCellEditor extends AbstractCellEditor implements TableCellEditor,ActionListener, SearchProduitEventListener {
private JComboBox combo;
private SearchProduitUi searchProduitUi;
private String value = "value";
public ProduitCellEditor() {
combo = new JComboBox();
combo.setEditable(true);
combo.setActionCommand("combo");
searchProduitUi = new SearchProduitUi();
searchProduitUi.setSearchProduitEventListener(this);
searchProduitUi.setSize(500,300);
searchProduitUi.setLocationRelativeTo(combo);
}
@Override
public Object getCellEditorValue() {
return value;
}
@Override
public Component getTableCellEditorComponent(JTable jtable, Object o, boolean bln, int i, int i1) {
return combo;
}
public void actionPerformed(ActionEvent event) {
Point comboPosition = combo.getLocationOnScreen();
searchProduitUi.setLocationRelativeTo(combo);
searchProduitUi.setLocation(comboPosition.x ,comboPosition.y + combo.getHeight());
searchProduitUi.setVisible(true);
}
@Override
public void searchDialogEventOccured(SearchProduitEvent ev) {
value = ev.getProduit().getDesignation();
fireEditingStopped();
}
}
【问题讨论】:
-
设置对话框不加修饰...
-
我已经做了 searchProduitUi.setUndecorated(true);但什么也没发生。
-
[在对话框语义的情况下] 请注意,作为用户,如果你阻止我移动窗口,无论是哪种类型的窗口,我都想开枪打死你。通常情况下,对话框所需的信息隐藏在对话框后面,如果你不让我移动对话框......在大多数窗口管理器上,我仍然可以将窗口移动到对话框后面,但是在外面-the-box MS Windows,我会迷路的。所以,我认为从可用性的角度来看,您想要实现的目标可能是有问题的。
-
[在 Popup 语义的情况下] 如果你的 Dialog 只是代表一个临时的东西,而不是一个真正的 Dialog,考虑一下如果 Window 被滚动或移动了怎么办?您的对话框的位置将不再正确。考虑改用
JGlassPane。
标签: java swing jtable tablecelleditor