E
Eustace
package temporary;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Temp extends JFrame {
Graphics2D painter2D;
static int W = 1200;
static int H = 600;
static int B = 10; // border
public Temp() {
super("Temp");
setSize(W + 8, H + 36); // necessary adjustment
System.out.println("1 " + getWidth() + " " + getHeight());
// 1 1208 636
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container contentArea = getContentPane();
CustomPanel panel = new CustomPanel();
contentArea.add(panel);
setContentPane(contentArea);
}
public static void main(String[] args) {
Temp instance = new Temp();
}
class CustomPanel extends JPanel {
public void paintComponent(Graphics painter) {
System.out.println("2 " + getWidth() + " " + getHeight());
// 2 1200 600
painter2D = (Graphics2D) painter;
painter2D.translate(0, H / 2); // middle horizontal 0
// draw the frame
Color clr = Color.black;
drawFrame(clr);
}
private void drawFrame(Color clr) {
double x, y, w, h;
x = 0 + B;
y = -H / 2 + B;
w = W - 2 * B;
h = H - 2 * B;
Rectangle2D.Double frame = new Rectangle2D.Double(x,y,w,h);
painter2D.setColor(clr);
painter2D.fill(frame);
}
}
}
In the above program, I want the active window (that is the area I am
working in, without the top bar and the borders) to be 1200 by 600. To
do so, I had to use
setSize(W + 8, H + 36);
to compensate for the width and height of the top bar and borders I have
in my system. If I do not make this adjustments, the frame will be
off-center. I found them empirically, by using
System.out.println("2 " + getWidth() + " " + getHeight());
within the
public void paintComponent(Graphics painter) {
Is there a way to get the necessary adjustment values of the system
automatically instead of empirically? Is there a way to reset the size
after I know the values of the adjustments in the
paintComponent(Graphics painter)?
Thanks,
emf
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Temp extends JFrame {
Graphics2D painter2D;
static int W = 1200;
static int H = 600;
static int B = 10; // border
public Temp() {
super("Temp");
setSize(W + 8, H + 36); // necessary adjustment
System.out.println("1 " + getWidth() + " " + getHeight());
// 1 1208 636
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container contentArea = getContentPane();
CustomPanel panel = new CustomPanel();
contentArea.add(panel);
setContentPane(contentArea);
}
public static void main(String[] args) {
Temp instance = new Temp();
}
class CustomPanel extends JPanel {
public void paintComponent(Graphics painter) {
System.out.println("2 " + getWidth() + " " + getHeight());
// 2 1200 600
painter2D = (Graphics2D) painter;
painter2D.translate(0, H / 2); // middle horizontal 0
// draw the frame
Color clr = Color.black;
drawFrame(clr);
}
private void drawFrame(Color clr) {
double x, y, w, h;
x = 0 + B;
y = -H / 2 + B;
w = W - 2 * B;
h = H - 2 * B;
Rectangle2D.Double frame = new Rectangle2D.Double(x,y,w,h);
painter2D.setColor(clr);
painter2D.fill(frame);
}
}
}
In the above program, I want the active window (that is the area I am
working in, without the top bar and the borders) to be 1200 by 600. To
do so, I had to use
setSize(W + 8, H + 36);
to compensate for the width and height of the top bar and borders I have
in my system. If I do not make this adjustments, the frame will be
off-center. I found them empirically, by using
System.out.println("2 " + getWidth() + " " + getHeight());
within the
public void paintComponent(Graphics painter) {
Is there a way to get the necessary adjustment values of the system
automatically instead of empirically? Is there a way to reset the size
after I know the values of the adjustments in the
paintComponent(Graphics painter)?
Thanks,
emf