List of usage examples for javax.swing JToolBar setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:us.physion.ovation.ui.editor.PlainTextVisualizationFactory.java
@Override public DataVisualization createVisualization(final Content r) { return new AbstractDataVisualization() { @Override/* w w w . j a v a 2 s. c o m*/ public JComponent generatePanel() { class PlainTextArea extends JTextArea { private boolean scrollableTracksViewportWidth = false; @Override public boolean getScrollableTracksViewportWidth() { return scrollableTracksViewportWidth; } private void setScrollableTracksViewportWidth(boolean b) { if (b == scrollableTracksViewportWidth) { return; } scrollableTracksViewportWidth = b; } private void failed() { setText(Bundle.LBL_TextLoadingFailed(ContentUtils.contentLabel(r))); } @Override public void addNotify() { super.addNotify(); ListenableFuture<File> data; try { data = r.getData(); } catch (ResourceNotFoundException ex) { log.warn("Resource not found", ex); failed(); return; } Futures.addCallback(data, new FutureCallback<File>() { @Override public void onSuccess(File f) { try { FileReader fr = new FileReader(f); try { final String text = IOUtils.toString(fr); EventQueue.invokeLater(new Runnable() { @Override public void run() { setText(text); setCaretPosition(0); repaint(); } }); } finally { IOUtils.closeQuietly(fr); } } catch (IOException ex) { log.warn("Could not load text", ex); failed(); } } @Override public void onFailure(Throwable ex) { log.warn("Could not get file", ex); failed(); } }, loadFileExecutors); } } final PlainTextArea t = new PlainTextArea(); t.setEditable(false); t.setText(Bundle.LBL_TextLoading()); ParentWidthPanel panel = new ParentWidthPanel(); panel.add(new JScrollPane(t), BorderLayout.CENTER); { JToolBar toolbar = new JToolBar(SwingConstants.HORIZONTAL); toolbar.setBackground(Color.WHITE); toolbar.add(new JToggleButton(new AbstractAction(Bundle.LBL_LineWrap()) { @Override public void actionPerformed(ActionEvent e) { boolean selected = ((JToggleButton) e.getSource()).isSelected(); t.setLineWrap(selected); t.setScrollableTracksViewportWidth(selected); t.setCaretPosition(0); t.revalidate(); t.repaint(); } })); panel.add(toolbar, BorderLayout.NORTH); } return panel; } @Override public boolean shouldAdd(Content r) { return false; } @Override public void add(Content r) { throw new UnsupportedOperationException(); } @Override public Iterable<? extends OvationEntity> getEntities() { return Sets.newHashSet((OvationEntity) r); } }; }