public void testGetSetUpdateUI() throws Exception { assertNotNull(pane.getUI()); ScrollPaneUI ui = new BasicScrollPaneUI(); pane.setUI(ui); assertEquals(ui, pane.getUI()); pane.updateUI(); assertNotSame(ui, pane.getUI()); }
@Override public void setUI(ScrollPaneUI ui) { super.setUI(ui); updateViewportBorder(); if (ui instanceof BasicScrollPaneUI) { try { Field field = BasicScrollPaneUI.class.getDeclaredField("mouseScrollListener"); field.setAccessible(true); Object value = field.get(ui); if (value instanceof MouseWheelListener) { MouseWheelListener oldListener = (MouseWheelListener)value; MouseWheelListener newListener = event -> { if (isScrollEvent(event)) { Object source = event.getSource(); if (source instanceof JScrollPane) { JScrollPane pane = (JScrollPane)source; if (pane.isWheelScrollingEnabled()) { JScrollBar bar = event.isShiftDown() ? pane.getHorizontalScrollBar() : pane.getVerticalScrollBar(); if (bar != null && bar.isVisible()) oldListener.mouseWheelMoved(event); } } } }; field.set(ui, newListener); // replace listener if field updated successfully removeMouseWheelListener(oldListener); addMouseWheelListener(newListener); } } catch (Exception exception) { LOG.warn(exception); } } }
@Override public void updateUI() { setUI(new BasicScrollPaneUI()); setBackground(ColorService.forCurrentTheme(Background)); }