Java 阻止 JApplet 组件根据 Applet 大小调整大小
创建 JApplet 我有 2 个文本字段、一个按钮和一个文本区域。
private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3));
private JPanel outputPanel = new JPanel(new GridLayout(1,1));
private JTextField serverTf = new JTextField("");
private JTextField pageTf = new JTextField("");
private JTextArea outputTa = new JTextArea();
private JButton connectBt = new JButton("Connect");
private JScrollPane outputSp = new JScrollPane(outputTa);
public void init()
{
setSize(500,500);
setLayout(new GridLayout(3,1));
add(addressEntryPanel);
addressEntryPanel.add(serverTf);
addressEntryPanel.add(pageTf);
addressEntryPanel.add(connectBt);
addressEntryPanel.setPreferredSize(new Dimension(50,50));
addressEntryPanel.setMaximumSize(addressEntryPanel.getPreferredSize());
addressEntryPanel.setMinimumSize(addressEntryPanel.getPreferredSize());
add(outputPanel);
outputPanel.add(outputSp);
outputTa.setLineWrap(true);
connectBt.addActionListener(this);
问题是当调试并将其放入页面时,组件/面板会根据小程序的大小调整大小。我不想要这个。我希望文本字段具有一定的大小,并且文本区域具有一定的大小。我已经在里面放了一些东西来设置它们的大小,但它们不起作用。我如何实际为组件或 JPanel 设置严格的大小。
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3));
private JPanel outputPanel = new JPanel(new GridLayout(1,1));
private JTextField serverTf = new JTextField("");
private JTextField pageTf = new JTextField("");
private JTextArea outputTa = new JTextArea();
private JButton connectBt = new JButton("Connect");
private JScrollPane outputSp = new JScrollPane(outputTa);
public void init()
{
setSize(500,500);
setLayout(new GridLayout(3,1));
add(addressEntryPanel);
addressEntryPanel.add(serverTf);
addressEntryPanel.add(pageTf);
addressEntryPanel.add(connectBt);
addressEntryPanel.setPreferredSize(new Dimension(50,50));
addressEntryPanel.setMaximumSize(addressEntryPanel.getPreferredSize());
addressEntryPanel.setMinimumSize(addressEntryPanel.getPreferredSize());
add(outputPanel);
outputPanel.add(outputSp);
outputTa.setLineWrap(true);
connectBt.addActionListener(this);
The problem is when debugging and putting it in a page the components / panels resize depending on the applet size. I don't want this. I want the textfields to be a certain size, and the text area to be a certain size. I've put stuff in there to set the size of them but they aren't working. How do I go about actually setting a strict size for either the components or the JPanel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个布局错误是忽略用户调整大小。
但是,您想要的可以通过不使用布局管理器来实现。即
The first layout sin is to ignore a user-resize.
However, what you want can be achieved by using no layout manager.That is