我正在尝试学习java教程,现在我正在学习JFrame。
这是一个信息查询而不是帮助问题。
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Login {
public static void main(String[] args){
//Creating object of LoginFrame class and setting some of its properties
LoginFrame frame = new LoginFrame();
frame.setTitle("LoginForm");
frame.setVisible(true);
frame.setBounds(10, 10, 370, 600);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}这段代码将导致框架在左上角调整为非常小的大小,而不考虑我设置的边界。
解决这个问题的一个简单方法是在设置其边界之前放置frame.setResizable()。
有没有人知道为什么会这样,或者我做错了什么?
我也在Ubuntu 20.04上,也许这很重要,但我还没有找到答案。
教程显示了上面的代码。
以下是LoginFrame的代码
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//Creating LoginFrame class
public class LoginFrame extends JFrame implements ActionListener {
//Creating constructor of LoginFrame() class
LoginFrame(){
}
//Overriding actionPerformed() method
@Override
public void actionPerformed(ActionEvent e){
}
}就像我说的,我只是在学习教程。这只是本教程的开始,但我在开始另一个非常简单的框架教程时遇到了同样的问题。
发布于 2021-08-04 23:58:04
下面的代码对我来说很好:
import javax.swing.*;
class Scratch extends JFrame {
public Scratch() {
super();
}
public static void main(String[] args){
//Creating object of LoginFrame class and setting some of its properties
Scratch frame = new Scratch();
frame.setTitle("LoginForm");
frame.setVisible(true);
frame.setBounds(10, 10, 370, 600);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}结果:我看到了一个很大的矩形窗口--我想是智能手机屏幕的形状。
setResizable(false)表示不能调整框架的大小。我怀疑您试图识别的问题存在于LoginFrame类中的某个地方……没有包含这方面的代码,尽管很难对此进行进一步的评论。
https://stackoverflow.com/questions/68659083
复制相似问题