首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >小程序组件不是VIsible

小程序组件不是VIsible
EN

Stack Overflow用户
提问于 2012-06-12 21:11:18
回答 1查看 2.4K关注 0票数 2

我将在登录后调用一个小程序类。窗体是可见的,但组件是不可见的,这是COuld的问题所在;这是我的类:

代码语言:javascript
复制
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package stanacle;


import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Calendar;
import javax.swing.JOptionPane;
/**
*
* @author Stano
*/
public class MenuOption extends JApplet{
Label header, menu, error, user;
TextField option;
Button go;

/**
 * Initialization method that will be called after the applet is loaded
 * into the browser.
 */
public void init() {
    // TODO start asynchronous download of heavy 
    setSize(1024, 768);
    setLayout(null);
    setVisible(true);
    header = new Label();
        menu = new Label();
        error = new Label();
        user = new Label();
        option = new TextField();
        go = new Button("GO");
        header.setBounds(370, 10, 200, 20);
        menu.setBounds(10, 60, 200, 20);
        option.setBounds(150, 60, 200, 20);
        go.setBounds(750, 10, 150, 30);
        error.setBounds(370, 310, 500, 20);
        user.setBounds(10, 10, 200, 20);
        header.setText("MENU OPTION PAGE");
        menu.setText("Enter Menu Option");


        add(header);
        add(menu);
        add(option);
        add(go);
        add(error);
        add(user);
}
// TODO overwrite start(), stop() and destroy() methods
}

窗体正在显示,但包括TextField、Labeld和按钮在内的组件未显示。COuld我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-12 21:22:04

1)代码行

代码语言:javascript
复制
setSize(1024, 768);
setLayout(null);
setVisible(true);

必须将最后几行代码放入public void init() {,因为您先显示容器,然后再添加J/Components

2)如果没有真正的原因(OpenGL,CAD / CAM),那么使用

  • Swing JApplet而不是史前的
  • Swing JComponents而不是AWT Components

3)不使用NullLayout

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10997409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档