- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何通过 JButton
操作调整 JWindow
的高度(我尝试了 setSize 和 repaint 但它不起作用)?
public class Gui extends JWindow implements KeyListener
{
public static Gui mystatic;
private static JPanel panelBgImg;
private final Dimension screen;
public static int w = 0;
public static int h = 0;
public void paintComponent(Graphics g)
{
}
public Dimension getPreferredSize()
{
return new Dimension(100, h);
}
public Gui()
{
....
/* Button 1 */
JButton jb2 = new JButton("")
{
public Dimension getPreferredSize()
{
return new Dimension(50,50);
}
};
jb2.setOpaque(false);
jb2.setContentAreaFilled(false);
jb2.setBorderPainted(false);
jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
h = 100;
/* HERE i am trying to resize the JWindow itself but not working
return new Dimension(100, h); */
mystatic.setSize(screen.width, 100);
mystatic.repaint();
}
});
...
}
最佳答案
例如
请不要在 EDT 期间使用 Thread.sleep(int)
,如本代码示例所示,它用于关闭当前 JVM 实例,否则该实例永远不会从 PC 的 RAM 中消失
import java.util.logging.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.*;
public class SSCCE {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
final JWindow window = new JWindow();
final JPanel windowContents = new JPanel();
JLabel label = new JLabel("A window that is pushed into view..........");
windowContents.add(label);
window.add(windowContents);
window.pack();
window.setLocationRelativeTo(null);
final int desiredWidth = window.getWidth();
window.getContentPane().setLayout(null);
window.setSize(0, window.getHeight());
window.setVisible(true);
Timer timer = new Timer(15, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int newWidth = Math.min(window.getWidth() + 1, desiredWidth);
window.setSize(newWidth, window.getHeight());
windowContents.setLocation(newWidth - desiredWidth, 0);
if (newWidth >= desiredWidth) {
((Timer) e.getSource()).stop();
//restore original layout
window.getContentPane().setLayout(new BorderLayout());
window.validate();
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(SSCCE.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);
}
}
});
timer.start();
}
private SSCCE() {
}
}
关于java - 如何使用 Java 中的 JButton 操作调整 JWindow 的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8653678/
是否可以在创建后将父窗口设置为JWindow?例如: public class SomeJWindow extends JWindow { public SomeJWindow (JFrame p
我如何才能只退出我从 Main 创建的新 MainGame?Main 有一个原始的游戏层。 MainGame 是一个对话窗口(例如模态窗口)。 Main.java:(主要代码) public clas
我创建了一个 java 程序,它不使用 JFrame,而是使用 JWindow。这正是我所需要的,一个没有窗口边框/标题栏的应用程序。 问题是它在运行时没有显示在屏幕底部的任务栏中。 谁能知道如何解决
我在使用 JWindow 时遇到问题。 这是我的包含 JWindow 的类: public class NextLevelCounter { JWindow window = new JWin
当我尝试将我的 JWindow 与 SeaGlass 一起使用时,它根本没有出现 Look and Feel ,即使我将其设置为可见。 import java.awt.EventQueue; impo
我创建了一个 java 程序,它不使用 JFrame,而是使用 JWindow。这正是我所需要的,一个没有窗口边框/标题栏的应用程序。 问题是它在运行时没有显示在屏幕底部的任务栏中。 谁能知道如何解决
我编写了一个 JWindow,用作我的桌面应用程序的启动屏幕。我遇到的问题是,窗口变得可见后,在显示预期图像之前它会暂时空白。空白窗口有时会保持 0.5 秒到 2 秒之间。我希望在窗口可见之前完全呈现
我使用了 Java 和 Swing。 我有两个窗口 MainWindow 和 PointWindow。 MainWindow 是一个 JFrame 窗口。 PointWindow 扩展 JWindow
我在我的小程序中创建了一个 JWindow 来显示更新过程,并将所有者设置为小程序父级。我的问题是 JWindow 在我浏览器的所有选项卡中都可见,而不仅仅是包含我的小程序的选项卡。是否可以添加一个监
我正在开发一个 toast 处理程序来管理通过“toast”动画(向上滑动,站立一会儿然后向下滑动)带给用户的通知。 Toast 类扩展了 JWindow(只是为了测试,我可以使用具有更稳定版本的 J
我想要做的是在我的程序加载某些内容时出现一个小的初始屏幕。这是我的: SplashScreen.showSplashScreen(); // Do stuff that takes time. Spl
我想创建一个 JWindow,它不仅具有不透明度,而且还想更改 Swing 内不透明度的默认颜色。 例如,如果我写: AWTUtilities.setWindowOpacity(this, 0.5f)
我想实现像截图工具一样的屏幕截图功能。我已经可以选择一个矩形并制作屏幕截图,但我这个矩形是完全不透明的。 我想知道 Swing 或 AWT 中是否有一个函数可以像这样使用: window.setOpa
我有一个 jwindow(设置为始终在顶部),您可以单击它以获取弹出菜单。如果用户右键单击该窗口,它会显示弹出菜单,但如果用户单击任何其他窗口(例如 firefox),弹出菜单不会消失。 我试图通过在
我正在编写这个程序来在 JWindow 中显示 JProgressbar。但是在同一台机器上运行这个程序而不做任何更改每次都会显示不同的结果。大多数时候它显示空的 JWindow,里面没有任何东西。其
我正在制作一个包含 JWindow 的 java 应用程序。我希望能够跟踪鼠标,而无需用户在转到另一个窗口后单击该窗口。 最佳答案 您的问题对于为什么要在鼠标离开 JWindow 后继续处理鼠标有点含
我正在制作一个自动完成项目(就像 Google 一样)。我的框架中有一个 jtextfield,每当我在该字段中键入内容时,文本字段下方都会出现一个 JWindow,并且该窗口来自另一个类。 现在的问
是否有一些方法可以知道类是否扩展JWindow?例如: class DialogWindow extends JWindow { } 如何检查 DialogWindow 类是否扩展 JWindow 类
我想在 JWindow 中显示一条消息一段时间,所以我尝试使用 while() 和 sleep() 函数,但它不起作用。这是应该调用 JWindow (MessageWindow) 的函数。有没有其他
我正在尝试对透明的JWindow进行双缓冲,但似乎所使用的技术不起作用(不同的周期值相互重叠)。 public final class Overlay extends JWindow { pu
我是一名优秀的程序员,十分优秀!