List of usage examples for javax.swing JScrollPane setViewport
@BeanProperty(expert = true, visualUpdate = true, description = "The viewport child for this scrollpane") public void setViewport(JViewport viewport)
From source file:Main.java
public static void main(String[] args) { JTextArea textArea = new JTextArea(5, 30); textArea.setOpaque(false);/* www . j av a 2s . c om*/ JViewport viewport = new JViewport() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int w = this.getWidth(); int h = this.getHeight(); g.setColor(Color.RED); g.fillRect(0, 0, w / 2, h / 2); } }; JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewport(viewport); scrollPane.setViewportView(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(scrollPane); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true); }
From source file:ScrollPaneWatermark.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); JTextArea ta = new JTextArea(); for (int i = 0; i < 1000; i++) { ta.append(Integer.toString(i) + " "); }//from ww w . ja va 2s . c o m ta.setLineWrap(true); ta.setWrapStyleWord(true); // ta.setOpaque(false); ScrollPaneWatermark watermark = new ScrollPaneWatermark(); watermark.setBackgroundTexture(new File("background.jpg").toURL()); watermark.setForegroundBadge(new File("foreground.png").toURL()); watermark.setView(ta); JScrollPane scroll = new JScrollPane(); scroll.setViewport(watermark); frame.getContentPane().add(scroll); frame.pack(); frame.setSize(600, 600); frame.setVisible(true); }
From source file:Main.java
public Main() { JViewport viewport = new MyViewport(); viewport.setView(new MyPanel()); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewport(viewport); add(scrollPane);//from www. j a v a 2s . c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); }
From source file:Main.java
MyPanel() { JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewport(viewport); viewport.add(innerPanel);//from ww w .j a v a 2 s.c o m scrollpane.setPreferredSize(SCROLLPANE_SIZE); viewport.addChangeListener(e -> { Rectangle viewRect = viewport.getViewRect(); if (viewRect.intersects(RECT)) { statusLabel.setText(VISIBLE); } else { statusLabel.setText(NOT_VISIBLE); } }); setLayout(new BorderLayout()); add(scrollpane, BorderLayout.CENTER); add(statusLabel, BorderLayout.SOUTH); }
From source file:JavaXWin.java
public JavaXWin() { setTitle("JavaXWin"); m_count = m_tencount = 0;/*from ww w. j ava2 s. c om*/ m_desktop = new JDesktopPane(); JScrollPane scroller = new JScrollPane(); m_wm = new WindowManager(m_desktop); m_desktop.setDesktopManager(m_wm); m_desktop.add(m_wm.getWindowWatcher(), JLayeredPane.PALETTE_LAYER); m_wm.getWindowWatcher().setBounds(555, 5, 200, 150); viewport = new JViewport() { public void setViewPosition(Point p) { super.setViewPosition(p); m_wm.getWindowWatcher().setLocation(m_wm.getWindowWatcher().getX() + (getViewPosition().x - m_wmX), m_wm.getWindowWatcher().getY() + (getViewPosition().y - m_wmY)); m_wmX = getViewPosition().x; m_wmY = getViewPosition().y; } }; viewport.setView(m_desktop); scroller.setViewport(viewport); ComponentAdapter ca = new ComponentAdapter() { JViewport view = viewport; public void componentResized(ComponentEvent e) { m_wm.getWindowWatcher().setLocation( view.getViewPosition().x + view.getWidth() - m_wm.getWindowWatcher().getWidth() - 15, view.getViewPosition().y + 5); } }; viewport.addComponentListener(ca); m_newFrame = new JButton("New Frame"); m_newFrame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { newFrame(); } }); JPanel topPanel = new JPanel(true); topPanel.setLayout(new FlowLayout()); getContentPane().setLayout(new BorderLayout()); getContentPane().add("North", topPanel); getContentPane().add("Center", scroller); topPanel.add(m_newFrame); Dimension dim = getToolkit().getScreenSize(); setSize(800, 600); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); m_desktop.setPreferredSize(new Dimension(1600, 1200)); setVisible(true); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); }