jframe

change JPanel after clicking on a button

本秂侑毒 提交于 2019-12-04 21:43:00
I'm building simple GUI for my app. I have couple of JPanels. I want to display them depending on action that was performed by clicking on a JButton. How can I disable one JPanel and enable another one ? Couple of details. I have a class with JFrame where I'm building starting gui. Where I have buttons and some text. Clicking on one of the buttons should change the view in this JFrame my button definition JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnStart.setBounds(10, 11, 110, 23); contentPane

Showing “JOptionPane.showMessageDialog” without stopping flow of execution

孤街浪徒 提交于 2019-12-04 21:10:09
问题 I'm currently working on a project that's getting more complex than I thought it would be originally. What I'm aiming to do right now is show a message dialog without halting the execution of the main thread in the program. Right now, I'm using: JOptionPane.showMessageDialog(null, message, "Received Message", JOptionPane.INFORMATION_MESSAGE); But this pauses everything else in the main thread so it won't show multiple dialogs at a time, just on after the other. Could this m=be as simple as

How to add imagepanel in jpanel inside Jframe?

﹥>﹥吖頭↗ 提交于 2019-12-04 20:22:10
I'm trying to add an imagepanel which extends JPanel to another JPanel. Which is not working well for me. The paint function of image panel don't get invoked inside Jpanel but works fine in JFrame. Any ideas or help will be appreciated. import javax.swing.*; import java.awt.*; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; class ImagePanel extends JPanel { int g_h=10,g_w=10; int width=50,height=50; int cornerradius; Image castle; Dimension size; protected int x1,y1; Color c1=new Color(255, 0, 0); Rectangle rec; boolean b=false; boolean imboo=false; boolean roundb=

java: How to add Transparent Gradient Background to JFrame

瘦欲@ 提交于 2019-12-04 20:18:32
java: I want to use the Gradient style Transparent Background to JFrame. On the top the transparency should be 100% but when going down it should go on decreasing and at the bottom it should be 20% I know i can use the images already having such effect but i want to provide the themes facility and allowing user to use their favorite images but allow transparency at the run time. Sun added support for translucent backgrounds to java in 6u10 but it is not formally described in the API. In Java 7 the functionality was formally added to the API via the setBackground(), setOpacity(), and setShape()

Swing - setResizable(true) make JFrame title bar higher and window size smaller

为君一笑 提交于 2019-12-04 19:26:33
In case someone marks it as duplicate, I will do it myself: we have a very relative question long before: Java setResizable(false) changes the window size (swing) And none solution works for me. Here is my SSCCE: import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.UIManager

Blink jframe in swing without transferring focus

人走茶凉 提交于 2019-12-04 19:17:16
I want to blink my jframe's entry in taskbar but do not want it to get focused. I read about in on net and tried different solutions but none of them worked for me. In my case I have a main jframe which has 2 buttons on click of which 2 jframes are opened. Both jframe listens to some event messages and on receiving of message it should blink if not focused. I have tried following: frame.toFront(); frame.requestFocus(); frame.firePropertyChange(); frame.setVisible(true); They all worked well in blinking windows but the focus also gets transfered to that window which I don't want it do. How can

How to center JPanel when JFrame is resized or maximized?

不羁岁月 提交于 2019-12-04 18:55:01
I want my JPanel to be still in the center when I maximize or re-size the JFrame . How can I do that? Tried: jframe.add(panel, BorderLayout.CENTER); panel.setAlignmentX(JComponent.CENTER_ALIGNMENT); But it doesn't work. Here is my other code: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { login frame = new login(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public login() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setBounds(5, 5, 409, 267); setLocationRelativeTo(null);

How do you open web pages in Java?

淺唱寂寞╮ 提交于 2019-12-04 17:13:47
问题 Is there a simple way to open a web page within a GUI's JPanel? If not, how do you open a web page with the computer's default web browser? I am hoping for something that I can do with under 20 lines of code, and at most would need to create one class. No reason for 20 though, just hoping for little code... I am planning to open a guide to go with a game. The guide is online and has multiple pages, but the pages link to each other, so I am hoping I only have to call one URL with my code. 回答1:

Two Different Panels in One Frame - Java

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:16
I have a question. I have one main frame, and to the left i have a sidebar with menus. My question is, is it possible to make another panel within the main frame, so that if menu1 is clicked, the related contents should be displayed to the second half of the main frame, and when other menus are pressed then obviously the relevant stuff according to what is selected. its a bit hard to explain, sorry. Has anyone got an idea, whether that is possible in Java with Eclipse? yes this's pretty possible you have look at CardLayout , this LayoutManager could be provide the simple way how to implement

how do i clear my frame screen in java?

痞子三分冷 提交于 2019-12-04 15:24:25
I am making a brick game. I want the screen to get clear after every 0.1 second so that i can redraw every thing on the frame screen. Is there any way to directly clear the frame screen without any event occurence?? You should override public void paint(Graphics g) and do all your drawing in there. Then you start a timer, which calls repaint(); Here is a basic example: public class MainFrame extends JFrame { int x = -1; int inc; public MainFrame() { Timer timer = new Timer(10, new ActionListener() { public void actionPerformed(ActionEvent arg0) { MainFrame.this.repaint(); } }); timer.start();