java AWT问题中的GridBagConstraints [英] GridBagConstraints in java AWT issue

查看:63
本文介绍了java AWT问题中的GridBagConstraints的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.awt.*;
import javax.swing.*;


JPanel middlePanel = new JPanel();
    middlePanel.setLayout(new GridBagLayout());
    
    GridBagConstraints cons = new GridBagContraints();
    cons.weightx = 1.0;
    cons.weighty = 1.0;
    middlePanel.setBorder(new TitledBorder(new EtchedBorder(),"Display Area"));





当我使用这段代码片段时(这只是一个粗略的代码片段)我得到的错误如找不到符号GridBagContraints和找不到符号TitledBorder,找不到符号EtchedBorder。如何解决?



When i use this code snippet(this is just a rough code snippet) i get errors like "can not find symbol GridBagContraints" and "can not find symbol TitledBorder","can not find symbol EtchedBorder". How to fix it?

推荐答案

错误告诉你是什么问题。您正在使用

The error told you what is the issue. You are using
GridBagConstraints cons = new GridBagContraints();





而不是



instead of

GridBagConstraints cons = new GridBagConstraints();





再次对于TitledBorder,你必须导入所需的api



And again in case of TitledBorder you have to import the required api

import javax.swing.border.TitledBorder


您缺少GridBagConstraints的导入规范,它似乎位于java.awt.GridBagConstraints中。如果你正在使用Eclipse,它会告诉你如果你将鼠标悬停在带有错误的语句上并且可以选择为你插入正确的包含。



再次相同(类似) TitledBorder的解决方案。
You are missing an import spec for GridBagConstraints, which seems to be in "java.awt.GridBagConstraints". If you are using Eclipse, it will tell you this if you hover over the statement with the error and will optionally insert the correct include for you.

Same again (similar solution) for TitledBorder.


感谢您的帮助......现在解决了。已进口



javax.swing.border.TitledBorder

javax.swing.border.EtchedBorder



并使拼写正确为GridBagConstraints cons = new ** GridBagConstraints()**;



而不是GridBagConstraints cons = new ** GridBagContraints() **;



再次感谢..:)



@ H.Brydon


@Shubhashish_Mandal
Thanks for helping..Its solved now. Imported

javax.swing.border.TitledBorder
javax.swing.border.EtchedBorder

And made the spelling correct for GridBagConstraints cons = new **GridBagConstraints()**;

instead of GridBagConstraints cons = new **GridBagContraints()**;

Thanks again..":)"

@H.Brydon

@Shubhashish_Mandal


这篇关于java AWT问题中的GridBagConstraints的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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