List of usage examples for javax.swing JToggleButton setToolTipText
@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.") public void setToolTipText(String text)
From source file:Main.java
public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText) { JToggleButton btn = new JToggleButton(); btn.setToolTipText(tooltipText); btn.setIcon(icon);//from w ww.jav a2 s . com btn.setMaximumSize(new Dimension(dimension, dimension)); btn.setMinimumSize(new Dimension(dimension, dimension)); btn.setPreferredSize(new Dimension(dimension, dimension)); btn.setMargin(new Insets(0, 0, 0, 0)); return btn; }
From source file:components.CrayonPanel.java
protected JToggleButton createCrayon(String name, Border normalBorder) { JToggleButton crayon = new JToggleButton(); crayon.setActionCommand(name);/* w ww . ja va2 s .c o m*/ crayon.addActionListener(this); //Set the image or, if that's invalid, equivalent text. ImageIcon icon = createImageIcon("images/" + name + ".gif"); if (icon != null) { crayon.setIcon(icon); crayon.setToolTipText("The " + name + " crayon"); crayon.setBorder(normalBorder); } else { crayon.setText("Image not found. This is the " + name + " button."); crayon.setFont(crayon.getFont().deriveFont(Font.ITALIC)); crayon.setHorizontalAlignment(JButton.HORIZONTAL); crayon.setBorder(BorderFactory.createLineBorder(Color.BLACK)); } return crayon; }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * Creates a diminutive toggle button used for selecting the message type * /* w ww.ja v a2 s . c o m*/ * @param title * the title of the button * @param icon * the icon to use * @param selected * whether the button is selected or not * @param group * the group to add the button to * @return the instantiated button */ private JToggleButton createMessageTypeButton(String title, ImageIcon icon, boolean selected, ButtonGroup group) { JToggleButton button = new JToggleButton(icon); group.add(button); button.setSelected(selected); button.setToolTipText(title); button.setFocusable(false); button.setFocusPainted(false); button.addActionListener(this); button.setPreferredSize(new Dimension(18, 18)); return button; }
From source file:be.nbb.demetra.dfm.DfmExecViewTopComponent.java
@Override public JComponent getToolbarRepresentation() { JToolBar toolBar = NbComponents.newInnerToolbar(); toolBar.addSeparator();//from w w w .j a v a 2 s . co m toolBar.add(Box.createRigidArea(new Dimension(5, 0))); JToggleButton startStop = (JToggleButton) toolBar .add(new JToggleButton(StartStopCommand.INSTANCE.toAction(this))); startStop.setIcon(DemetraUiIcon.COMPILE_16); startStop.setDisabledIcon(createDisabledIcon(startStop.getIcon())); startStop.setToolTipText("Start/Stop"); JButton edit = toolBar.add(EditSpecCommand.INSTANCE.toAction(this)); edit.setIcon(DemetraUiIcon.PREFERENCES); edit.setDisabledIcon(createDisabledIcon(edit.getIcon())); edit.setToolTipText("Specification"); JButton clear = toolBar.add(ClearCommand.INSTANCE.toAction(this)); clear.setIcon(DemetraUiIcon.EDIT_CLEAR_16); clear.setDisabledIcon(createDisabledIcon(clear.getIcon())); clear.setToolTipText("Clear"); SwingColorSchemeSupport colorSchemeSupport = SwingColorSchemeSupport .from(DemetraUI.getInstance().getColorScheme()); sparkline = (ChartPanel) toolBar .add(Charts.avoidScaling(new ChartPanel(Charts.createSparkLineChart(null)))); sparkline.setPreferredSize(new Dimension(150, 16)); sparkline.setMaximumSize(new Dimension(150, 16)); sparkline.getChart().getXYPlot().setDataset(dataset); sparkline.getChart().getXYPlot().getRenderer() .setBasePaint(colorSchemeSupport.getLineColor(ColorScheme.KnownColor.GREEN)); sparkline.setBackground(colorSchemeSupport.getPlotColor()); sparkline.setBorder(BorderFactory.createLineBorder(colorSchemeSupport.getGridColor())); sparkline.setToolTipText("loglikelihood"); return toolBar; }
From source file:org.geopublishing.atlasViewer.swing.AtlasChartJPanel.java
/** * Creates a {@link JToolBar} that has buttons to interact with the Chart * and it's SelectionModel./*from w w w .ja v a2s . c o m*/ * * @return */ public JToolBar getToolBar() { if (toolBar == null) { toolBar = new JToolBar(); toolBar.setFloatable(false); ButtonGroup bg = new ButtonGroup(); /** * Add an Action to ZOOM/MOVE in the chart */ JToggleButton zoomToolButton = new SmallToggleButton(new AbstractAction("", ICON_ZOOM) { @Override public void actionPerformed(ActionEvent e) { getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.ZOOM_IN_CHART); } }, GpCoreUtil.R("AtlasChartJPanel.zoom.tt")); toolBar.add(zoomToolButton); bg.add(zoomToolButton); toolBar.addSeparator(); /** * Add an Action not change the selection but just move through the * chart */ JToggleButton setSelectionButton = new SmallToggleButton(new AbstractAction("", ICON_SELECTION_SET) { @Override public void actionPerformed(ActionEvent e) { getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_SET); } }); setSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.SetSelection.TT")); toolBar.add(setSelectionButton); bg.add(setSelectionButton); /** * Add an Action to ADD the selection. */ JToggleButton addSelectionButton = new SmallToggleButton(new AbstractAction("", ICON_SELECTION_ADD) { @Override public void actionPerformed(ActionEvent e) { getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_ADD); } }); addSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.AddSelection.TT")); toolBar.add(addSelectionButton); bg.add(addSelectionButton); /** * Add an Action to REMOVE the selection. */ JToggleButton removeSelectionButton = new SmallToggleButton( new AbstractAction("", ICON_SELECTION_REMOVE) { @Override public void actionPerformed(ActionEvent e) { getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_REMOVE); } }); removeSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.RemoveSelection.TT")); toolBar.add(removeSelectionButton); bg.add(removeSelectionButton); toolBar.addSeparator(); /** * Add a normal Button to clear the selection. The Chart's selection * models are cleared. If a relation to a JMapPane exists, they will * be synchronized. */ final SmallButton clearSelectionButton = new SmallButton(new AbstractAction("", ICON_SELECTION_CLEAR) { @Override public void actionPerformed(ActionEvent e) { // getSelectionModel().clearSelection(); // get the selectionmodel(s) of the chart List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil .getFeatureDatasetSelectionModelFor(getSelectableChartPanel().getChart()); for (FeatureDatasetSelectionModel dsm : datasetSelectionModelFor) { dsm.clearSelection(); } } }, MapPaneToolBar.R("MapPaneButtons.Selection.ClearSelection.TT")); { // Add listeners to the selection model, so we knwo when to // disable/enable the button // get the selectionmodel(s) of the chart List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil .getFeatureDatasetSelectionModelFor(getSelectableChartPanel().getChart()); for (final FeatureDatasetSelectionModel selModel : datasetSelectionModelFor) { DatasetSelectionListener listener_ClearSelectionButtonEnbled = new DatasetSelectionListener() { @Override public void selectionChanged(DatasetSelectionChangeEvent e) { if (!e.getSource().getValueIsAdjusting()) { // Update the clearSelectionButton clearSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0); } } }; insertedListeners.add(listener_ClearSelectionButtonEnbled); selModel.addSelectionListener(listener_ClearSelectionButtonEnbled); clearSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0); } } toolBar.add(clearSelectionButton); toolBar.addSeparator(); /** * Add a normal Button which opens the Chart'S print dialog */ SmallButton printChartButton = new SmallButton(new AbstractAction("", Icons.ICON_PRINT_24) { @Override public void actionPerformed(ActionEvent e) { getSelectableChartPanel().createChartPrintJob(); } }); printChartButton.setToolTipText(GpCoreUtil.R("AtlasChartJPanel.PrintChartButton.TT")); toolBar.add(printChartButton); /** * Add a normal Button which opens the Chart's export/save dialog */ SmallButton saveChartAction = new SmallButton(new AbstractAction("", Icons.ICON_SAVEAS_24) { @Override public void actionPerformed(ActionEvent e) { try { getSelectableChartPanel().doSaveAs(); } catch (IOException e1) { LOGGER.info("Saving a chart to file failed", e1); ExceptionDialog.show(AtlasChartJPanel.this, e1); } } }); saveChartAction.setToolTipText(GpCoreUtil.R("AtlasChartJPanel.SaveChartButton.TT")); toolBar.add(saveChartAction); // // A JButton to open the attribute table // { final JButton openTable = new JButton(); openTable.setAction(new AbstractAction(GpCoreUtil.R("LayerToolMenu.table"), Icons.ICON_TABLE) { @Override public void actionPerformed(final ActionEvent e) { AVDialogManager.dm_AttributeTable.getInstanceFor(styledLayer, AtlasChartJPanel.this, styledLayer, mapLegend); } }); toolBar.addSeparator(); toolBar.add(openTable); } /* * Select/set data points button is activated by default */ getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_SET); setSelectionButton.setSelected(true); } return toolBar; }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JToggleButton createMouseModeButton(final AbstractModalGraphMouse graphMouse) { final String selectText = "Move graph"; final JToggleButton button = new JToggleButton(selectText); button.setToolTipText("If toggled then you can move the entire graph."); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (button.isSelected()) { graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); } else { graphMouse.setMode(ModalGraphMouse.Mode.PICKING); }//w w w . j a v a2s. c om } }); return button; }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
private void buildMenu() { JXTaskPane editPane = new JXTaskPane(); editPane.setTitle("Bearbeiten"); final JToggleButton createStats = new JToggleButton( new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/medal.png"))); createStats.setToolTipText( "Umschalten zwischen dem Erzeugen von Statistiken und der Anzeige von Verlaufsgrafiken"); createStats.addMouseListener(new MouseAdapter() { @Override/*from w w w .j ava 2s. c o m*/ public void mouseReleased(MouseEvent e) { boolean showChartView = !createStats.isSelected(); if (showChartView) { createStats .setIcon(new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/medal.png"))); } else { createStats .setIcon(new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/chart.png"))); } switchStatChartView(showChartView); } }); JXButton selectStart = new JXButton( new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/beginning.png"))); selectStart.setToolTipText("Setzt eine Startmarkierung beim gewhlten Datenpunkt"); selectStart.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { setStartAnnotation(); } }); selectStart.setSize(createStats.getSize()); selectStart.setMinimumSize(createStats.getMinimumSize()); selectStart.setMaximumSize(createStats.getMaximumSize()); selectStart.setPreferredSize(createStats.getPreferredSize()); editPane.getContentPane().add(selectStart); JXButton selectEnd = new JXButton( new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/end.png"))); selectEnd.setToolTipText("Setzt eine Endmarkierung beim gewhlten Datenpunkt"); selectEnd.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { setEndAnnotation(); } }); selectEnd.setSize(createStats.getSize()); selectEnd.setMinimumSize(createStats.getMinimumSize()); selectEnd.setMaximumSize(createStats.getMaximumSize()); selectEnd.setPreferredSize(createStats.getPreferredSize()); editPane.getContentPane().add(selectEnd); JXButton removeSelection = new JXButton( new ImageIcon(DSWorkbenchChurchFrame.class.getResource("/res/ui/delete_region.png"))); removeSelection.setToolTipText("Lscht alle Datenpunkte zwischen der Start- und Endmarkierung"); removeSelection.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { removeSelection(); } }); removeSelection.setSize(createStats.getSize()); removeSelection.setMinimumSize(createStats.getMinimumSize()); removeSelection.setMaximumSize(createStats.getMaximumSize()); removeSelection.setPreferredSize(createStats.getPreferredSize()); editPane.getContentPane().add(removeSelection); createStats.setSize(removeSelection.getSize()); createStats.setMinimumSize(removeSelection.getMinimumSize()); createStats.setMaximumSize(removeSelection.getMaximumSize()); createStats.setPreferredSize(removeSelection.getPreferredSize()); editPane.getContentPane().add(createStats); JXTaskPane viewPane = new JXTaskPane(); viewPane.setTitle("Anzeige"); viewPane.getContentPane().add(jViewSelectionBox); JXTaskPane settingsPane = new JXTaskPane(); settingsPane.setTitle("Einstellungen"); settingsPane.getContentPane().add(jShowItemValues); settingsPane.getContentPane().add(jShowLegend); settingsPane.getContentPane().add(jShowLines); settingsPane.getContentPane().add(jShowDataPoints); centerPanel.setupTaskPane(editPane, viewPane, settingsPane); }
From source file:net.schweerelos.parrot.CombinedParrotApp.java
@SuppressWarnings("serial") private JToggleButton setupNavigatorButton(final String name, final String accelerator, final NavigatorComponent navigator) { final Component component = navigator.asJComponent(); AbstractAction showNavigatorAction = new AbstractAction(name) { @Override// w w w. ja v a 2 s .c o m public void actionPerformed(ActionEvent e) { if (!(e.getSource() instanceof JToggleButton)) { return; } final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } JToggleButton button = (JToggleButton) e.getSource(); boolean show = button.isSelected(); if (show) { if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) { window.setLocation(preferredFrameLocations.get(window)); } } if (navigator.tellSelectionWhenShown()) { Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes(); navigator.setSelectedNodes(selectedNodes); } component.setVisible(show); if (show) { window.setVisible(true); } else if (window != CombinedParrotApp.this) { window.setVisible(false); } } }; showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator)); final JToggleButton button = new JToggleButton(showNavigatorAction); button.setToolTipText("Show " + name.toLowerCase()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase()); } }); final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } if (window != null) { window.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { button.setSelected(false); if (window != CombinedParrotApp.this) { preferredFrameLocations.put(window, window.getLocation()); } } @Override public void componentShown(ComponentEvent e) { button.setSelected(true); } }); } return button; }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void setupButton(JToggleButton button, String toolTipText, String rolloverImg, String selectedImg) {/* w ww .j a va2 s. c o m*/ button.setFont(new Font("Dialog", Font.PLAIN, 12)); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.CENTER); button.setText(toolTipText); button.setRolloverIcon(new ImageIcon(Constants.IMG_FOLDER + rolloverImg)); button.setSelectedIcon(new ImageIcon(Constants.IMG_FOLDER + selectedImg)); button.setBackground(m_selected_but_color); button.setToolTipText(toolTipText); // Remove border Border emptyBorder = BorderFactory.createEmptyBorder(); button.setBorder(emptyBorder); // Set adequate size button.setPreferredSize(new Dimension(32, 32)); }
From source file:op.care.med.inventory.PnlInventory.java
private CollapsiblePane createCP4(final MedInventory inventory) { /***// w ww . j ava 2s . c om * _ ____ ____ _ _ _____ _ __ * ___ _ __ ___ __ _| |_ ___ / ___| _ \| || | / /_ _|_ ____ _____ _ __ | |_ ___ _ __ _ \ \ * / __| '__/ _ \/ _` | __/ _ \ | | |_) | || |_| | | || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | | * | (__| | | __/ (_| | || __/ |___| __/|__ _| | | || | | \ V / __/ | | | || (_) | | | |_| | | * \___|_| \___|\__,_|\__\___|\____|_| |_| | ||___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | | * \_\ |___/_/ */ final String key = inventory.getID() + ".xinventory"; synchronized (cpMap) { if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try { cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } cpMap.get(key).setName("inventory"); // final CollapsiblePane cpInventory = cpMap.get(key); BigDecimal sumInventory = BigDecimal.ZERO; try { EntityManager em = OPDE.createEM(); sumInventory = MedInventoryTools.getSum(em, inventory); em.close(); } catch (Exception e) { OPDE.fatal(e); } String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"520\" align=\"left\"><font size=+1>" + inventory.getText() + "</font></td>" + "<td width=\"200\" align=\"right\"><font size=+1>" + NumberFormat.getNumberInstance().format(sumInventory) + " " + DosageFormTools.getPackageText(MedInventoryTools.getForm(inventory)) + "</font></td>" + "</tr>" + "</table>" + "</html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cpMap.get(key).setCollapsed(!cpMap.get(key).isCollapsed()); } catch (PropertyVetoException pve) { // BAH! } } }); cpMap.get(key).setTitleLabelComponent(cptitle.getMain()); cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH); cptitle.getButton().setIcon(inventory.isClosed() ? SYSConst.icon22stopSign : null); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) { /*** * ____ _ ___ _ * / ___| | ___ ___ ___|_ _|_ ____ _____ _ __ | |_ ___ _ __ _ _ * | | | |/ _ \/ __|/ _ \| || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | * | |___| | (_) \__ \ __/| || | | \ V / __/ | | | || (_) | | | |_| | * \____|_|\___/|___/\___|___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | * |___/ */ final JButton btnCloseInventory = new JButton(SYSConst.icon22playerStop); btnCloseInventory.setPressedIcon(SYSConst.icon22playerStopPressed); btnCloseInventory.setAlignmentX(Component.RIGHT_ALIGNMENT); btnCloseInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnCloseInventory.setContentAreaFilled(false); btnCloseInventory.setBorder(null); btnCloseInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btncloseinventory.tooltip")); btnCloseInventory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("nursingrecords.inventory.question.close1") + "<br/><b>" + inventory.getText() + "</b>" + "<br/>" + SYSTools.xx("nursingrecords.inventory.question.close2"), SYSConst.icon48playerStop, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedInventory myInventory = em.merge(inventory); em.lock(myInventory, LockModeType.OPTIMISTIC); em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC); // close all stocks for (MedStock stock : MedStockTools.getAll(myInventory)) { if (!stock.isClosed()) { MedStock mystock = em.merge(stock); em.lock(mystock, LockModeType.OPTIMISTIC); mystock.setNextStock(null); MedStockTools.close(em, mystock, SYSTools.xx( "nursingrecords.inventory.stock.msg.inventory_closed"), MedStockTransactionTools.STATE_EDIT_INVENTORY_CLOSED); } } // close inventory myInventory.setTo(new Date()); em.getTransaction().commit(); createCP4(myInventory); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnCloseInventory.setEnabled(!inventory.isClosed()); cptitle.getRight().add(btnCloseInventory); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) { /*** * ____ _ ___ _ * | _ \ ___| |_ _|_ ____ _____ _ __ | |_ ___ _ __ _ _ * | | | |/ _ \ || || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | * | |_| | __/ || || | | \ V / __/ | | | || (_) | | | |_| | * |____/ \___|_|___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | * |___/ */ final JButton btnDelInventory = new JButton(SYSConst.icon22delete); btnDelInventory.setPressedIcon(SYSConst.icon22deletePressed); btnDelInventory.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnDelInventory.setContentAreaFilled(false); btnDelInventory.setBorder(null); btnDelInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btndelinventory.tooltip")); btnDelInventory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("nursingrecords.inventory.question.delete1") + "<br/><b>" + inventory.getText() + "</b>" + "<br/>" + SYSTools.xx("nursingrecords.inventory.question.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedInventory myInventory = em.merge(inventory); em.lock(myInventory, LockModeType.OPTIMISTIC); em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC); em.remove(myInventory); em.getTransaction().commit(); // lstInventories.remove(inventory); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); cptitle.getRight().add(btnDelInventory); } final JToggleButton tbClosedStock = GUITools.getNiceToggleButton(null); tbClosedStock.setToolTipText(SYSTools.xx("nursingrecords.inventory.showclosedstocks")); if (!inventory.isClosed()) { tbClosedStock.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } }); } tbClosedStock.setSelected(inventory.isClosed()); tbClosedStock.setEnabled(!inventory.isClosed()); mapKey2ClosedToggleButton.put(key, tbClosedStock); cptitle.getRight().add(tbClosedStock); CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } }; synchronized (cpListener) { if (cpListener.containsKey(key)) { cpMap.get(key).removeCollapsiblePaneListener(cpListener.get(key)); } cpListener.put(key, adapter); cpMap.get(key).addCollapsiblePaneListener(adapter); } if (!cpMap.get(key).isCollapsed()) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING); cpMap.get(key).setOpaque(false); cpMap.get(key).setBackground(getColor(SYSConst.medium2, lstInventories.indexOf(inventory) % 2 != 0)); return cpMap.get(key); } }