SizeGrip sg = new SizeGrip(); sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround panel.add(sg, BorderLayout.LINE_END); MouseInputAdapter adapter = new MouseInputAdapter() {
SizeGrip() { MouseHandler adapter = new MouseHandler(); addMouseListener(adapter); addMouseMotionListener(adapter); setPreferredSize(new Dimension(16, 16)); }
@Override public void updateUI() { super.updateUI(); // TODO: Key off of Aqua LaF, not just OS X, as this size grip looks // bad on other LaFs on Mac such as Nimbus. if (System.getProperty("os.name").contains("OS X")) { if (osxSizeGrip==null) { osxSizeGrip = createOSXSizeGrip(); } } else { // Clear memory in case of runtime LaF change. osxSizeGrip = null; } }
/** * Ensures that the cursor for this component is appropriate for the * orientation. * * @param ltr Whether the current component orientation is LTR. */ protected void possiblyFixCursor(boolean ltr) { int cursor = Cursor.NE_RESIZE_CURSOR; if (ltr) { cursor = Cursor.NW_RESIZE_CURSOR; } if (cursor!=getCursor().getType()) { setCursor(Cursor.getPredefinedCursor(cursor)); } }
Dimension dim = getSize(); ComponentOrientation orientation = getComponentOrientation();
/** * Overridden to ensure that the cursor for this component is appropriate * for the orientation. * * @param o The new orientation. */ @Override public void applyComponentOrientation(ComponentOrientation o) { possiblyFixCursor(o.isLeftToRight()); super.applyComponentOrientation(o); }
@Override public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
/** * Ensures that the cursor for this component is appropriate for the * orientation. * * @param ltr Whether the current component orientation is LTR. */ protected void possiblyFixCursor(boolean ltr) { int cursor = Cursor.NE_RESIZE_CURSOR; if (ltr) { cursor = Cursor.NW_RESIZE_CURSOR; } if (cursor!=getCursor().getType()) { setCursor(Cursor.getPredefinedCursor(cursor)); } }
Dimension dim = getSize(); ComponentOrientation orientation = getComponentOrientation();
/** * Overridden to ensure that the cursor for this component is appropriate * for the orientation. * * @param o The new orientation. */ public void applyComponentOrientation(ComponentOrientation o) { possiblyFixCursor(o.isLeftToRight()); super.applyComponentOrientation(o); }
@Override public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
SizeGrip() { MouseHandler adapter = new MouseHandler(); addMouseListener(adapter); addMouseMotionListener(adapter); setPreferredSize(new Dimension(16, 16)); }
SizeGrip sg = new SizeGrip(); sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround panel.add(sg, BorderLayout.LINE_END); MouseInputAdapter adapter = new MouseInputAdapter() {
/** * Ensures that the cursor for this component is appropriate for the * orientation. * * @param ltr Whether the current component orientation is LTR. */ protected void possiblyFixCursor(boolean ltr) { int cursor = Cursor.NE_RESIZE_CURSOR; if (ltr) { cursor = Cursor.NW_RESIZE_CURSOR; } if (cursor!=getCursor().getType()) { setCursor(Cursor.getPredefinedCursor(cursor)); } }
Dimension dim = getSize(); Color c1 = UIManager.getColor("Label.disabledShadow"); Color c2 = UIManager.getColor("Label.disabledForeground"); ComponentOrientation orientation = getComponentOrientation();
/** * Overridden to ensure that the cursor for this component is appropriate * for the orientation. * * @param o The new orientation. */ @Override public void applyComponentOrientation(ComponentOrientation o) { possiblyFixCursor(o.isLeftToRight()); super.applyComponentOrientation(o); }
public void updateUI() { super.updateUI(); // TODO: Key off of Aqua LaF, not just OS X, as this size grip looks // bad on other LaFs on Mac such as Nimbus. if (System.getProperty("os.name").indexOf("OS X")>-1) { if (osxSizeGrip==null) { osxSizeGrip = createOSXSizeGrip(); } } else { // Clear memory in case of runtime LaF change. osxSizeGrip = null; } }
public void mouseDragged(MouseEvent e) { Point newPos = e.getPoint(); SwingUtilities.convertPointToScreen(newPos, SizeGrip.this); int xDelta = newPos.x - origPos.x; int yDelta = newPos.y - origPos.y; Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this); if (wind!=null) { // Should always be true if (getComponentOrientation().isLeftToRight()) { int w = wind.getWidth(); if (newPos.x>=wind.getX()) { w += xDelta; } int h = wind.getHeight(); if (newPos.y>=wind.getY()) { h += yDelta; } wind.setSize(w,h); } else { // RTL int newW = Math.max(1, wind.getWidth()-xDelta); int newH = Math.max(1, wind.getHeight()+yDelta); wind.setBounds(newPos.x, wind.getY(), newW, newH); } // invalidate()/validate() needed pre-1.6. wind.invalidate(); wind.validate(); } origPos.setLocation(newPos); }
public SizeGrip() { MouseHandler adapter = new MouseHandler(); addMouseListener(adapter); addMouseMotionListener(adapter); setPreferredSize(new Dimension(16, 16)); }
SizeGrip sg = new SizeGrip(); sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround panel.add(sg, BorderLayout.LINE_END); MouseInputAdapter adapter = new MouseInputAdapter() {