Tag: 摇摆

JTable行限制

我必须限制JTable的行数。 如果我有100条记录,我需要在初始加载JTable时显示10条。 我想放一个像”next”的按钮,每次点击后它会显示另一组10条记录。

将图像设置为JPanel背景的最简单方法

如何在不创建新类或方法的情况下将背景图像添加到JPanel,只需将其与JPanel的其余属性一起插入即可? 我试图使用图像设置JPanel的背景,但是,我发现的每个示例似乎都建议使用自己的类扩展面板。 我一直在寻找一种方法来简单地添加图像,而无需创建一个全新的类并在同一个方法中(尝试保持组织和简单)。 以下是设置JPanel的方法示例: public static JPanel drawGamePanel(){ //Create game panel and attributes JPanel gamePanel = new JPanel(); Image background = Toolkit.getDefaultToolkit().createImage(“Background.png”); gamePanel.drawImage(background, 0, 0, null); //Set Return return gamePanel; }

使用前景标签将图像添加到Jbutton

朋友们,我尝试使用seticon方法将图像添加到我的Jbutton,但它隐藏了按钮上的文本标签。 这是代码: try { Image img = ImageIO.read(getClass().getResource(“image.jpg”)); studentsButton.setIcon(new ImageIcon(img)); } catch (IOException ex) { } 我在没有init()/ paint()/ graphics的eclipse中使用swing,它在main方法中的简单框架。

Java中的主线程与UI线程

在这里作为答案给出的许多Swing片段中,从main方法调用SwingUtilities#invokeLater : public class MyOneClassUiApp { private constructUi() { // Some Ui related Code } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new MyOneClassUiApp().constructUi(); } }); } } 但根据Threads and Swing的文章 ,从主线程构造UI是安全的: 一些方法是线程安全的:在Swing API文档中,线程安全的方法用这个文本标记: 虽然大多数Swing方法都不是,但这种方法是线程安全的。 应用程序的GUI通常可以构造并显示在主线程中:只要没有实现组件(Swing或其他),以下典型代码是安全的: public class MyApplication { public static void main(String[] args) { JFrame f = […]