Last active
March 10, 2019 12:20
-
-
Save ezhov-da/2f3244e2670f36833bc50c4f2af7ab19 to your computer and use it in GitHub Desktop.
java расположение окна около кнопки пуск
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[code:]java[:code] | |
import java.awt.Component; | |
import java.awt.Dimension; | |
import java.awt.GraphicsEnvironment; | |
import java.awt.Rectangle; | |
import java.awt.Toolkit; | |
import java.util.logging.Logger; | |
import javax.swing.JFrame; | |
/** | |
* Класс, который распологает любой компонент в углу пагнели задач | |
* <p> | |
* @author ezhov_da | |
*/ | |
public class LocatedComponent | |
{ | |
private static final Logger LOG = Logger.getLogger(LocatedComponentInTheCorner.class.getName()); | |
public static void main(String[] args) | |
{ | |
JFrame frame = new JFrame(); | |
frame.setSize(400, 400); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
locatedInTheCorner(frame); | |
frame.setVisible(true); | |
} | |
public static void locatedInTheCorner(Component component) | |
{ | |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
Rectangle rect = ge.getMaximumWindowBounds(); | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |
if (rect.getHeight() < screenSize.height & rect.y != 0) | |
{ | |
System.out.println("UP"); | |
component.setLocation(screenSize.width - component.getWidth(), rect.y); | |
} else if (rect.getHeight() < screenSize.height & rect.y == 0) | |
{ | |
System.out.println("DOWN"); | |
component.setLocation(screenSize.width - component.getWidth(), rect.height - component.getHeight()); | |
} else if (rect.getWidth() < screenSize.width & rect.x == 0) | |
{ | |
System.out.println("RIGHT"); | |
component.setLocation(rect.width - component.getWidth(), screenSize.height - component.getHeight()); | |
} else if (rect.getWidth() < screenSize.width & rect.x != 0) | |
{ | |
System.out.println("LEFT"); | |
component.setLocation(rect.x, screenSize.height - component.getHeight()); | |
} | |
} | |
} | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment