jviewport

How to pan an image using your mouse in Java Swing

╄→尐↘猪︶ㄣ 提交于 2019-12-30 03:27:08
问题 I am creating a Java app that will allow users to view images and to pan the image using their mouse. To implement the panning of the image I use a combination of mouseClicked and mouseDragged events using JViewports. The bulk of the code is in the mouseDragged method public void mouseDragged(MouseEvent e, WindowWrapper w) { final JViewport vp = someFieldViewPort; //Getting the point that the mouse is dragged to to Point cp = e.getPoint(); final Point vPoint = vp.getViewPosition(); //I found

Enabling auto resize of JTable only if it fit viewport

这一生的挚爱 提交于 2019-12-18 04:36:08
问题 I need to create a JTable inside JScrollPane with resizeable columns (when user increase column width - horizontal scrollbar appears). For this I have use table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); . Also, when viewport is wide enough to contain entire table - columns should stretch to fill viewport width. To accomplish this I have override getScrollableTracksViewportWidth() method of JTable class as follow: @Override public boolean getScrollableTracksViewportWidth() { return

JTable how to change BackGround Color

血红的双手。 提交于 2019-12-17 03:20:29
问题 I inspired by MeBigFatGuy interesting question, in this conection I have very specific question about Graphisc2D , how to change BackGround Color by depends if is JTables Row visible in the JViewPort , 1) if 1st. & last JTables Row will be visible in the JViewPort , then BackGround would be colored to the Color.red 2) if 1st. & last JTables Row will not be visible in the JViewPort , then BackGround would be colored to the Color.whatever from SSCCE import java.awt.*; import java.awt.event

JTable how to change BackGround Color

一个人想着一个人 提交于 2019-12-17 03:20:09
问题 I inspired by MeBigFatGuy interesting question, in this conection I have very specific question about Graphisc2D , how to change BackGround Color by depends if is JTables Row visible in the JViewPort , 1) if 1st. & last JTables Row will be visible in the JViewPort , then BackGround would be colored to the Color.red 2) if 1st. & last JTables Row will not be visible in the JViewPort , then BackGround would be colored to the Color.whatever from SSCCE import java.awt.*; import java.awt.event

Scrolling JComponent in JScrollPane

非 Y 不嫁゛ 提交于 2019-12-11 08:28:10
问题 Say, I have a big JComponent: Dimension componentSize = new Dimension(5000,5000); And a smaller JScrollPane: Dimension scrollPaneSize = new Dimension(500,500); I want to display part of my JComponent in JScrollPane, like on the picture below: White rectangle is my JScrollPane, which currently displays part of JComponent from (x1,y1) to (x2,y2) . So, what have I tried: I have created a new JComponent: JComponent component = new JComponent(){ protected void paintComponent(Graphics g) { // Here

uncatchable error with JViewport.setView

前提是你 提交于 2019-12-11 07:58:51
问题 I CANNOT provide an SSCCE as I can't make error repeatable outside of my large App. But here is a snippet and the output: if (vp != null) { try { starterModule.writePaneln("Sigma.show() 4.1 vp: "+vp); starterModule.writePaneln("Sigma.show() 4.1 P: "+P); starterModule.writePaneln("Sigma.show() 4.1 scrollPane: "+scrollPane); vp.setView(P); starterModule.writePaneln("Sigma.show() 4.2"); } catch (Exception e) { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C:\\javaout2.txt"

JScrollPane adjustmentListener and scrollRectToVisible

戏子无情 提交于 2019-12-11 05:53:47
问题 I need to handle event from JScrollPane when user scrolls it. In here it is suggested to use addAdjustmentListener to either JViewport or Vertical/HorizontalScrollBar. Is there any difference, which method should I choose? I would like also to use scrollRectToVisible for the same JScrollPane , should I anticipate AdjustmentListener working for this method? Also I wonder whether scrollRectToVisible tries to do minimum scrolling to make required rectangular visible or it tries to make it

Scrolling limitation with JScrollPane and JViewport maximum sizes smaller than contents

别来无恙 提交于 2019-12-01 23:42:51
问题 I have a JFrame containing a JScrollPane containing a JPanel . The JPanel contains a bunch of JTextArea s. I'm loading a lot of text into them (about 8k-10k characters). The layout works fine, though the scrolling is a bit laggy. The real issue is that it seems JPanel , JScrollPane and JViewport have a hard 32767 size limit, so when any JTextArea grows higher than that, it can't be scrolled any further to show the last 1/3 of the text. Below you can see a minimal example for the problem. I

Scrolling limitation with JScrollPane and JViewport maximum sizes smaller than contents

Deadly 提交于 2019-12-01 22:33:30
I have a JFrame containing a JScrollPane containing a JPanel . The JPanel contains a bunch of JTextArea s. I'm loading a lot of text into them (about 8k-10k characters). The layout works fine, though the scrolling is a bit laggy. The real issue is that it seems JPanel , JScrollPane and JViewport have a hard 32767 size limit, so when any JTextArea grows higher than that, it can't be scrolled any further to show the last 1/3 of the text. Below you can see a minimal example for the problem. I used the NetBeans JFrame designer so it might be a bit lengthy but the only thing I have changed from the

How to pan an image using your mouse in Java Swing

六月ゝ 毕业季﹏ 提交于 2019-11-30 10:01:35
I am creating a Java app that will allow users to view images and to pan the image using their mouse. To implement the panning of the image I use a combination of mouseClicked and mouseDragged events using JViewports. The bulk of the code is in the mouseDragged method public void mouseDragged(MouseEvent e, WindowWrapper w) { final JViewport vp = someFieldViewPort; //Getting the point that the mouse is dragged to to Point cp = e.getPoint(); final Point vPoint = vp.getViewPosition(); //I found the image went off the content to show the white border so I included this // Here pp is a field that I