- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我自定义了 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();
}
}
最佳答案
JDialog#setUndecorated
将删除框架装饰,包括关闭/最小化/最大化控件,并使用户无法移动窗口。
import java.awt.EventQueue;
import java.awt.GridBagLayout;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
public class Test1 {
public static void main(String[] args) {
new Test1();
}
public Test1() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
JPanel content = new JPanel(new GridBagLayout());
content.setBorder(new EmptyBorder(8, 8, 8, 8));
JLabel label = new JLabel("Hello world");
content.add(label);
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
dialog.setTitle("Testing");
dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
dialog.setContentPane(content);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
});
}
}
关于java - JDialog不可移动窗体JTable单元格编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27769384/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!