swing

Close window - but don't stop program - JAVA

纵饮孤独 提交于 2021-02-05 08:09:15
问题 In my program it opens a window if an action is happened. After I have filled out information in this window, and entered a button, the window dispose(). The window is picked up in a program outside my main program, but when I close this window, my main program stops. How can I prevent this from happening? Thanks for your help! 回答1: You can set the defalaultCloseOperation property of the second frame to DO_NOTHING_ON_CLOSE or DISPOSE_ON_CLOSE Don't even use two frames. Use a modal JDialog

Set Label in Java to Image-Format Issue

孤人 提交于 2021-02-05 08:08:00
问题 I am trying to set the label in a java program to an image. It seems, however, that it does not work for .bmp images I am looking for a converter which will allow me to convert an image from a .bmp to a .jpg with the same file name. This converter needs to be controlled by the java program, which has the name and location of the image that needs to be converted. Any help would be greatly appreciated as I have spent hours on this :P Thanks *Edit: The program needs to be able to be packaged

Set Label in Java to Image-Format Issue

走远了吗. 提交于 2021-02-05 08:07:43
问题 I am trying to set the label in a java program to an image. It seems, however, that it does not work for .bmp images I am looking for a converter which will allow me to convert an image from a .bmp to a .jpg with the same file name. This converter needs to be controlled by the java program, which has the name and location of the image that needs to be converted. Any help would be greatly appreciated as I have spent hours on this :P Thanks *Edit: The program needs to be able to be packaged

JFreeChart - XYLineAndShapeRenderer getItemLineVisible() not working

此生再无相见时 提交于 2021-02-05 08:00:31
问题 I'm simulating dummy real-time data using DynamicTimeSeriesCollection, like this. During random intervals, the data being passed to the plot should 'dropout' to simulate a network connection loss. At this point, this plot should stop drawing and only start plotting the data after the dropout has subsided. I subclassed XYLineAndShapeRenderer and overrode the getItemLineVisible() method: @Override public boolean getItemLineVisible(int series, int item){ if(offline){ return false; }else{ return

Java Swing: How to get TextArea value including the char just typed?

一个人想着一个人 提交于 2021-02-05 07:59:09
问题 What's the best way to get a value of a TextArea after a key is typed, including this character? If I do it in the even listener, textarea.getText() returns the value without the eventual new char. Basically I see two ways: postponing processing with something like invokeLater(). I would prefer a solution without threads. figuring out where to put the char into the text, based on the carret position. Is there any other, simpler? Thanks. Edit: This is what I have: JTextArea textarea =

Dynamic JFreeChart TimeSeries

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 07:57:28
问题 [EDIT] Based on this example, I am now able to collect data and display it in a chart. I don't know exactly how to integrate that code that generates the chart into my application. /** @see http://stackoverflow.com/questions/5048852 */ public class Atol extends ApplicationFrame { private static final String TITLE = "Dynamic Series"; private static final String START = "Start"; private static final String STOP = "Stop"; private static final float MINMAX = 100; private static final int COUNT =

How to align multiple elements below each other?

本小妞迷上赌 提交于 2021-02-05 07:36:38
问题 I am having difficulty in aligning Swing elements flow below each other. Using GridLayout does not help me because it divides screen to rows which have equal sizes. I need to put one component to each row and the next component should be in very bottom of the last component. Mi problem is that if the choices of the question are more than one line, this layout squeeze them to the rows and there is a huge gap between picture and question "3+3?" 回答1: You can use GridBagLayout for this. It is

How to add a border to a rectangle in Java using setBorder and JFrame

戏子无情 提交于 2021-02-05 07:15:05
问题 I am trying to add a border to a Rectangle element and for some reason it will not work, is it not compatible with JFrame ? I can set my entire JFrame to having a border, but it can't find setBorder with my rectangles. Here is my code: package trivia; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.border

Revalidate JPanel's parent frame

安稳与你 提交于 2021-02-05 07:09:25
问题 I want my panel to fit the frame when I show/hide fields. How could I notify to the parent frame to revalidate? I thought about pass the frame to my panel's constructor, but I think may have a way this is already done. I remember that there was a protected attribute in JPanel, but there isn't.. maybe i remembering the wrong component. 回答1: I need show/hide some fields of my panel, and I want the panel to fit the frame. You mean like a summary/details view and you want the frame size to change

Robot class java , typing a string issue

ⅰ亾dé卋堺 提交于 2021-02-05 06:11:46
问题 I m using the following loop , but its only typing the first charecter and the rest as numbers, any idea ? import java.awt.*; import javax.swing.KeyStroke; public class test { public static void main(String[] args) throws AWTException { Robot r = new Robot(); String s = "Face"; for (int i = 0; i < s.length(); i++) { char res = s.charAt(i); r.keyPress(res); r.keyRelease(res); r.delay(1000); } } } OUTPUT typing : F135 回答1: The keyPress/Release methods need an int value that represents the