javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
FontUIResource f = new FontUIResource(new Font("Verdana", 0, 12); Enumeration<Object> keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof FontUIResource) { FontUIResource orig = (FontUIResource) value; Font font = new Font(f.getFontName(), orig.getStyle(), f.getSize()); UIManager.put(key, new FontUIResource(font)); } }
int reply = JOptionPane.showConfirmDialog(null, "Is Hello world?", "Title", JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION){ //do something }
JComponent[] inputs // int reply = JOptionPane.showConfirmDialog(null, inputs, "", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (reply == JOptionPane.OK_OPTION) { ...
UIManager.put("OptionPane.yesButtonText", ""); UIManager.put("OptionPane.noButtonText", ""); UIManager.put("OptionPane.cancelButtonText", ""); UIManager.put("OptionPane.okButtonText", "");
myapplet.getAudioClip(MyPlayerClass.class.getResource(" ").play();
public class MyTable extends JTable { public class MyButtonRenderer extends JButton implements TableCellRenderer, TableCellEditor{ private int selectedRow; private int selectedColumn; private final List<MyButtonListener> listener = new ArrayList<MyButtonListener>(); public MyButtonRenderer() { super(); addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for (MyButtonListener l : listener) { l.tableButtonClicked(selectedRow, selectedColumn); // } } }); } public Component getTableCellRendererComponent(JTable a, Object b, boolean c, boolean d, int e, int f) { setFocusable(false); return this; } public boolean stopCellEditing() {return true;} public Object getCellEditorValue() { return null;} public boolean isCellEditable(EventObject anEvent) { return true;} public boolean shouldSelectCell(EventObject anEvent) {return true;} public Component getTableCellEditorComponent(JTable a, Object b, boolean c, int d, int e) { selectedRow = row; selectedColumn = column; setFocusable(false); return this; } public void addTableButtonListener(ITableButtonListener l) {listener.add(l);} public void removeTableButtonListener(ITableButtonListener l) {listener.remove(l);} } public MyTable(){ MyButtonRenderer button = new MyButtonRenderer(); button.addTableButtonListener(new MyButtonListenerImpl()); // "" . 2 this.getColumnModel().getColumn(0).setCellRenderer(new MyButtonRenderer()); this.getColumnModel().getColumn(0).setCellEditor(button); } public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer result = super.getCellRenderer(row, column); if (result instanceof MyButtonRenderer) return result; return < ( )>; } }
class MyWorker extends SwingWorker<Void, MyObject>{ private IProxyObject action; protected SwingWorkerReal(MyObject data){ this.action = data; } protected Void doInBackground() throws Exception { if (action != null) publish(action); return null; } protected void process(List<MyObject> chunks) { // process! } } ... new MyWorker(data).execute(); // ... }
Source: https://habr.com/ru/post/137347/