H
HannesG
Gast
Mit welcher Klasse geht das?
Hobbit_Im_Blutrausch hat gesagt.:Toolkit
class MyDockedWindow extends ComponentAdapter
{
public void componentMoved(ComponentEvent e)
{
System.out.println("Höhe Desktop: " + dim.getHeight() + "Breite Desktop: " + dim.getWidth());
if(fenster.getLocation().x == (dim.getWidth() - 390) && fenster.getLocation().y == (dim.getHeight() - 530));
{
System.out.println("Angedockt!");
fenster.setLocation((int)dim.getWidth()- 380,(int)dim.getHeight() - 520);
}
}
}
fenster.setLocation((int)dim.getWidth()-380,(int)dim.getHeight()-(int)dim.getHeight());
Hobbit_Im_Blutrausch hat gesagt.:OK, und jetzt nochmal langsam zum Mitschreiben: Was geht jetzt genau nicht und wie soll es gehen?
public class DockingWindow extends JFrame
{
static final long serialVersionUID = 1L;
static DockingWindow myWindow;
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
public DockingWindow() throws IOException
{
super("Docking Window");
myWindow = this;
addComponentListener(new MyDockedWindow());
}
class MyDockedWindow extends ComponentAdapter
{
public void componentMoved(ComponentEvent e)
{
//System.out.println("myWindow Position-x: " +myWindow.getLocation().x+"myWindow Position-y: " +myWindow.getLocation().y );
//if(myWindow.getLocation().x > (dim.getWidth() - 390) && myWindow.getLocation().y > (dim.getHeight() - 530));
if(myWindow.getLocation().x > 1290);
{
System.out.println("Angedockt!");
//myWindow.setLocation((int)dim.getWidth()- 380,(int)dim.getHeight() - 520);
myWindow.setLocation((int)dim.getWidth()-380,(int)dim.getHeight()-(int)dim.getHeight());
}
}
}
public static void main(String args[])throws Exception
{
DockingWindow myWindow = new DockingWindow();
myWindow.setSize(380,520);
myWindow.setLocationRelativeTo(null);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setResizable(false);
myWindow.setVisible(true);
}
}
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.IOException;
import javax.swing.JFrame;
public class DockingWindow extends JFrame {
static final long serialVersionUID = 1L;
static DockingWindow myWindow;
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
public DockingWindow() throws IOException {
super("Docking Window");
myWindow = this;
addComponentListener(new MyDockedWindow());
}
class MyDockedWindow extends ComponentAdapter {
public void componentMoved(ComponentEvent e) {
//Fensterposition ermitteln
Point location = myWindow.getLocation();
double location_X = location.getX();
double location_Y = location.getY();
//5 mögliche Andockbereiche
//1. links
//2. links oben
//3. oben
//4. rechts oben
//5. rechts
//links oben prüfen
if (location_X <= 25 && location_Y <= 25) {
myWindow.setLocation(0, 0);
//links profen
} else if (location_X <= 25) {
myWindow.setLocation(0, (int) location_Y);
//oben rechts prüfen
} else if (location_X >= dim.width - (25 + myWindow.getWidth()) && location_Y <= 25) {
myWindow.setLocation(dim.width - myWindow.getWidth(), 0);
//rechts prüfen
} else if(location_X >= dim.width - (25 + myWindow.getWidth())){
myWindow.setLocation(dim.width - myWindow.getWidth(), (int)location_Y);
//oben prüfen
} else if (location_Y <= 25) {
myWindow.setLocation((int) location_X, 0);
}
}
}
public static void main(String args[]) throws Exception {
DockingWindow myWindow = new DockingWindow();
myWindow.setSize(380, 520);
myWindow.setLocationRelativeTo(null);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setResizable(false);
myWindow.setVisible(true);
}
}
*Hendrik hat gesagt.:...weil Du hinter Deiner if-Bedingung ein Semikolon hast.
Code:if(myWindow.getLocation().x > 1290);
HannesG hat gesagt.:*Hendrik hat gesagt.:...weil Du hinter Deiner if-Bedingung ein Semikolon hast.
Code:if(myWindow.getLocation().x > 1290);
sigh! :autsch: komisch warum eclipse net gemeckert hat da?
Hobbit_Im_Blutrausch hat gesagt.:Flackert es, während du es "andocken" lässt? Und davor und danach nicht mehr? Oder wie ist das zu verstehen?
Hobbit_Im_Blutrausch hat gesagt.:dann verwende doch Looks von JGoodies. Ist auch schön anzusehen.
Hobbit_Im_Blutrausch hat gesagt.:ne, ich weiß net mehr. Aber JGoodies hat auch sehr schöne LaFs und ein versuch is es doch allemal wert
![]()