更改我的小程序同样在eclipse&QUOT大小;运行小程序" [英] Changing the size for my applet also in eclipse "run as applet"

查看:140
本文介绍了更改我的小程序同样在eclipse&QUOT大小;运行小程序"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在做我的第一个小程序。虽然测试结果我希望能够在preVIEW窗口Eclipse中运行它,而不是总是部署小程序到一个罐子,并在浏览器中打开页面(浏览器缓存杀死我!我总是需要重新启动浏览器...)

I am currently doing my first applet. While testing the results I want to be able to run it in eclipse in the preview windows instead of always deploying the applet into a jar and opening the page in the browser (the browser cache kills me! I always need to restart the browser...)

反正当我试图与运行应用程序为运行 - > Java小程序,我得到了preVIEW,但它总是非常小(猜下面200×200)。当我每手改变大小,窗长,但内容留小。当我打电话的setSize(宽,高)窗口启动越大,内容保持小。小,并不意味着其按比例缩小,这意味着我只看到黑色面板,白色酮(它是在浏览器中可见的)是不可见的,以便其不似乎被缩放...

Anyway, when I try to run the app with "run as -> Java Applet" I got the preview but its always very small (guess below 200x200). When I change the size per hand, the window grows but the content stay that small. When I call setSize(width, height) the window starts bigger, the content stays small. Small doesn't mean its scaled down, it means that I only see the black panel, the white one (which is visible in the browser) is not visible so its not seemed to be scaled...

我是什么失踪?

我的code到目前为止(其工作方式类似于预计在560宽度和高度500的broswer)

My code so far (which works like expected in the broswer with width of 560 and height of 500)

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Benchmark extends JApplet {
 private static final long serialVersionUID = -8767182603875435760L;

 GridLayout gridLayout = new GridLayout(7, 1);
 JButton startTests = new JButton("Start");
 JPanel testPanel = new JPanel();
 JPanel topPanel = new JPanel();

 @Override
 public void init() {
  super.init();
  try {
   java.awt.EventQueue.invokeAndWait(new Runnable() {
    public void run() {
     initComponents();
     invalidate();
    }
   });
  } catch (Exception ex) {
   ex.printStackTrace();
  }
 }

 public void initComponents() {
     setSize(660, 500);
     topPanel.setBackground(Color.BLACK);
     topPanel.setSize(500, 500);

     testPanel.setBackground(Color.WHITE);
     testPanel.setSize(160, 500);

     getContentPane().add(topPanel, BorderLayout.WEST);
     getContentPane().add(testPanel, BorderLayout.EAST);
     testPanel.setLayout(gridLayout);
     testPanel.add(new JLabel("Triangles"));
     testPanel.add(new JLabel("Pyramids"));
     testPanel.add(new JLabel("Cubes"));
     testPanel.add(new JLabel("Blending"));
     testPanel.add(new JLabel("Spheres"));
     testPanel.add(new JLabel("Lights"));
     testPanel.add(new JLabel("Mass"));
 }
}

截图应显示的问题。如果窗口拥有660x500的大小(设定的setSize()可见区域保持小:

The screenshot should show the problem. If the window has the size of 660x500 (set with setSize() the visible area stays small:

推荐答案

您窗口的大小设置为500,500,所以它这种规模的黑盒子。如果你扩大你的屏幕右侧​​的面板是可见的。

Your size of the window is set to 500,500 and so it this size of your black box. The panel on the right is visible if you widen your screen.

用于设置大小和最小值,最大值和preferred大小为 topPanel 删除code。然后,而不是将它添加到 BorderLayout.WEST ,使用 BorderLayout.CENTER 来代替。这将允许测试板留在左侧和作为窗口调整大小将调整的黑盒子。

Remove the code for setting a size and a min,max, and preferred size for the topPanel. Then instead of adding it to BorderLayout.WEST, use BorderLayout.CENTER instead. This will allow the test panel to stay on the left and will resize your black box as the window resizes.

这篇关于更改我的小程序同样在eclipse&QUOT大小;运行小程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆