-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCenteFrame.java
More file actions
59 lines (43 loc) · 2.29 KB
/
CenteFrame.java
File metadata and controls
59 lines (43 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//*****************************************************************
// CenteFrame.java Author: Ravyar Sarbast
//
// The Center Frame where we put all of widgets in it
//*****************************************************************
package RavyarSarbastTahir;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.*;
public class CenteFrame extends JFrame {
public CenteFrame() throws HeadlessException {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {// setting layout to nimbus as it look great
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
UIManager.put("nimbusBase", Color.white);// setting global setting instead of item by item
// it look greater and the app will have uniform look
UIManager.put("control", Color.white);
UIManager.put("MenuItem[MouseOver].textForeground", Color.BLUE);
UIManager.put("MenuBar:Menu[Selected].textForeground", Color.lightGray);
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
}
public void centerScreen() { // normal way to center app on screen
Toolkit tookkit = getToolkit();
Dimension dimensionOfScreen = tookkit.getScreenSize();
setSize(dimensionOfScreen.width / 2, dimensionOfScreen.height / 2);//we setup the frame to be half of screen size
setLocation(new Point(dimensionOfScreen.width / 4, dimensionOfScreen.height / 4));// we setup the frame to be in middle of screen
}
public void centerScreen(int x, int y, JFrame oldframe) {// for smaller window that I create later in the app
Toolkit tookkit = getToolkit();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
Dimension dimensionOfScreen = tookkit.getScreenSize();
setSize(dimensionOfScreen.width / 6, dimensionOfScreen.height / 6);//we setup the frame to be half of screen size
x = (oldframe.getLocation().x) + x;
y = (oldframe.getLocation().y) + y;
setLocation(new Point(x, y));// we setup the frame to be in middle of screen
}
}