Tag: jframe

在java中的Jframe上绘制简单的矩形

我正在扩展JFrame,如下所示: public GameFrame() { this.setBounds(30, 30, 500, 500); this.setDefaultCloseOperation(EXIT_ON_CLOSE); initializeSquares(); } private void initializeSquares(){ for(int i = 0; i < 5; i++){ this.getContentPane().add(new Square(i*10, i*10, 100, 100)); } this.setVisible(true); } 但是,屏幕上只绘制了一个正方形,有人知道为什么吗? 我的Square类看起来像这样: private int x; private int y; private int width; private int height; public Square(int x, int y, int width, int height){ this.x = […]

使用JFrame的setIconImages()方法的图标大小是多少?

有没有人知道哪些图标大小与jFrame的setIconImages()(PLURAL)方法一起使用,以便我的应用程序图标在所有平台和所有上下文中都能很好地显示(例如,窗口图标,任务栏图标,alt-tab图标等。 )? 我找到了一个使用16px-by-16px和32px-by-32px图像的示例,但是我需要更大吗? 为了测试,我还尝试将64px和128px版本添加到传递给setIconImages()的List中,但这些版本似乎没有在我的Windows 7机器上使用。 但是,我无法在其他机器上轻松测试,所以我想知道是否有人知道我应该包括哪些尺寸?

如何在JTable中添加JCheckBox?

首先,我为我的英语疏忽道歉,我将解释我的所有问题。 首先,我想要JTable中的JCheckBox。 我正在从索引0和1列中的数据库中检索学生ID和学生姓名。我希望第三列应该是缺席/现在,这将最初取决于学生是否存在JCheckbox Value。 这里是JTable值的代码: Attendance.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package shreesai; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.Vector; /** * * @author Admin */ public class Attendance{ Connection con = Connectdatabase.ConnecrDb(); public Vector getEmployee()throws Exception { Vector<Vector> employeeVector […]

如何设置jframe外观

我有点困惑在哪里把这个: try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); UIManager.setLookAndFeel(“com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”); } catch(Exception e){ } 我没有扩展JFrame类,但使用了JFrame f = new JFrame(); 感谢:D

在java swing中设置窗口的最小大小限制

我有一个JFrame ,在GridBagLayout中有3个JPanel .. 现在,当我最小化窗口时,在一定限制之后,第三个JPanel趋于消失。 我尝试使用setMinimumSize(new Dimension(int,int))设置最小化JFrame的大小但没有成功。 窗户仍然可以最小化。 所以,我实际上想做一个门槛,我的窗口在一定限度后无法最小化。 我怎么能这样做? 码:- import java.awt.Dimension; import javax.swing.JFrame; public class JFrameExample { public static void main(String[] args) { JFrame frame = new JFrame(“Hello World”); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(400, 400)); frame.setVisible(true); } } 也: shadyabhi@shadyabhi-desktop:~/java$ java –showversion java version “1.5.0” gij (GNU libgcj) version 4.4.1 Copyright (C) 2007 Free Software Foundation, […]

如何在CardLayout中显示不同的卡?

我查看了使用此代码的代码示例: cl.show(cardPanel, “” + (currentCard)); 但是当我使用show时,我在Eclipse中收到一条消息,它已被弃用,我想知道当我点击按钮时是否还有另一种方法可以显示CardLayout中的不同卡片? 下面是我的CardLayout类的代码。 如果代码的某些部分是不好的做法,也欢迎提出建议。 谢谢! import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class CardLayoutTest extends JFrame implements ActionListener { // Ref private JPanel cardPanel, jp1, jp2, buttonPanel; private JLabel jl1, jl2; private JButton btn1, btn2; private CardLayout cardLayout; // Konstruktor public CardLayoutTest() { setTitle(“Test med CardLayout”); setSize(600,400); cardPanel = […]

为什么人们在事件队列上运行Java GUI

在Java中,要创建并显示一个新的JFrame ,我只需这样做: public static void main(String[] args) { new MyCustomFrameClass().setVisible(true); } 但是,我见过很多人这样做: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { new MyCustomFrameClass().setVisible(true); } }); } 为什么? 有什么好处吗?

将在一个JFrame文本字段中输入的值作为其他JFrame中的输入参数传递

如何将在一个JFrame文本字段中输入的值作为输入参数传递给其他JFrame? 通过JTextFields在第一个JFrame输入用户名和密码.. String usr = jTextField2.getText(); String pass = jTextField3.getText(); 相同的用户名和密码应在第四帧中作为输入给出,每个帧在按钮点击时被重定向到其他帧

Java Swing JFrame布局

我刚刚编写了一个简单的代码,我希望在主框架上显示一个文本字段和一个按钮,但是在运行之后,我看到的是文本字段。 如果我在文本字段后面写了按钮的代码,那么只显示按钮。 知道为什么吗? JFrame mainframe=new JFrame(); mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainframe.setBounds(0,0,200,200); JButton jb=new JButton(); jb.setText(“Leech”); mainframe.add(jb); JTextField link=new JTextField(50); mainframe.add(link); mainframe.pack(); mainframe.setVisible(true);

JavaFX 2.2阶段始终位于顶部

我有一个普通的JFrame(应用程序的一部分)和第二个JavaFX窗口(我不能在JavaFX阶段使用JFrame)。 问题是JavaFX窗口应始终位于所有其他窗口之上。 我不知道如何解决这个问题! 有任何想法吗?