So I'm stumped. I, for some reason, seem to remember that Java does weird things when you try to add new lines to stuff... so I think that may be the problem here.
This code is not working how you'd expect it to:
public void displayText(KeyEvent k){
txt = inputArea.getText();
outputArea.setText(txt);
if(k.getKeyCode() == 1...
Hi!
Has anyone ever tried to change swing's look and feel? This code, taken from an example, simply yields a null pointer exception, and I wonder what might be wrong:
(javax.swing.UIManager/setLookAndFeel
(javax.swing.UIManager/getSystemLookAndFeelClassName))
Thanks!
...
Background
So I read that often memory leaks within Swing applications originate from the use of various listeners (mouse, key, focus, etc). Essentially, you register an object as a listener and forget to deregister the object, the notifier ends up holding onto the reference of the object, leaking a bit of memory.
I knew our applicatio...
Is it possible to have a minimize and maximize button for a non-modal(modal=false) JDialog.I know JFrame is the ideal solution for this but this change has to be made in an existing code and its little difficult to change from JDialog to JFrame.
...
I am trying to have a circle appear on the screen, then when the user clicks INSIDE the circle, enable the ability for them to drag the circle where the mouse goes while it is being pressed.
This is the code i have so far, the drag works, but it is allowing the user to drag without them pressing the inside of the circle, just when anywh...
I developed a java application with netbeans. It used jdk 1.6.
It works fine.
But now the requirement is I need to build the jar for the application from the .java files in another machine without netbeans and where jdk 1.5 is used. I cannot upgrade that machine to jdk 1.6.
Is there any way I could make my java files compile and work ...
Hello,
I'm having a problem and hope, someone knows what's going wrong and why and is able to give me the explanation of what I'm missing out right now to make that thing work as suggested.
I have a JTree which is build upon a custom TreeModel ("WRTreeModel", see below).
The data structure this model shall be used for is build of an ro...
Hello,
I've been given a bunch of messy code and a short time limit (no surprises there) to write some tests for it. I have written tests! They are good tests.
Unfortunately, instantiating some of the project's components causes Swing GUI elements to be constructed and set visible too. I don't want this to happen for obvious reasons, s...
Hi,
I've implemented a simple mouse listener where the background color changes whenever the mouse enters the component (a JPanel), and it reverts back whenever the mouse leaves. This has some problems:
Sometimes the mouse moves so quick that the mouseExit event is not fired
If my component has childs, when the mouse moves to the chil...
I deal with numeric data that is often edited up or down by 0.01*Value_of_variable, so a spinner looks like a good choice compared to a usual text cell.
I've looked at DefaultCellEditor but it will only take text fields, combo boxes or check boxes.
Is there a convenient way to use a spinner?
...
According to the Javadoc, JComponent.repaint(long) is supposed to schedule a repaint() sometime in the future. When I try using it it always triggers an immediate repaint. What am I doing wrong?
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;...
I have created JToolBar (Java Swing). I have set a Background image on frame which contains JToolBar. I want my JToolBar to be transparent so that the image kept on frame should be visible. I am using setOpaque(false) but it is not having any effect on my toolbar.. Has anyone delt with this before? My Code is as follows
import javax.swi...
I'm looking for a way to pass mouse events to components covered by other components. To illustrate what I mean, here's a sample code. It contains two JLabels, one is twice smaller and entirely covered with a bigger label. If you mouse over the labels, only the bigger one fires mouseEntered event however.
import java.awt.Color;
import j...
I have a Swing application and I'm trying to fade out the main application and show a window saying an operation is in progress (this is for long running operations that may need to block the UI). Is there an elegant way to do this in Swing (mainly the fading out the background) or maybe some swing library to help with this (maybe from s...
I want to create button with custome look and feel. I have got different images to be set as background of button for normal, mouse over, mouse click, button disabled etc. I have created my own class, extending javax.swing.JButton and overrides paintComponent method. How can i change my button background for all the above given states.
...
I have a main frame which has a menu bar and let user to change the font of all the texts in my program.I can just set the font for the main frame but how can i set that change for all my frames and dialogs???
...
I have created customized Button. For that i have overrided paintComponenet method. How can I set Button Text on such button? I tried doing it using drawString method. But which x,y values should i give? (g.drawString("button text",x,y)). Please till me if anyone has handled this.
@Override
public void paintComponent(Graphics g) {
s...
There are already some questions about how to set a default file name for a JFileChooser control.
I'm having a few problems with preserving that default filename when switching directories.
Right now, when I do that, the original filename I supplied get over overwritten by the path of the new directory itself.
Is there anything can be ...
Hi, I'm wondering about the standard practice with inner classes (in Java but I suppose it applies to all OO languages).
So I have a JFrame subclass ControllerWindow that contains a JPanel subclass MapPanel which I draw onto (so it needs to overwrite paintComponent method) and which needs to implement a mouse listener. My current solutio...
I'm doing a Java application that requires to use a web browser inside the application.
I have seen some applications doing this, such as RSS readers when clicking in a feed in the left panel and opening the link in a right panel in the same application, and I would like to implement something similar.
Is it possible to do this in java...