I am trying to use Swing Timer and I wanted to start from a very simple program. I have a window with text: "You have n seconds", where n changes from 10 to 0 every second.
I know how to generate a window with text. And I understand how Timer works (it starts an action periodically). But I cannot figure out how to combing this two thing...
Here is the code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;
public class TimerSample {
public static void main(String args[]) {
new JFrame().setVisible(true);
ActionListener actionListener = new ActionListener() {
public void actionPerf...
I would like to know if this is a good idea that conforms to best practices that does not lead to obscenely confusing code or major performance hit(s):
Make my own Collision detection class that extends Rectangle class.
Then when instantiating that object doing something such as Collision col = new Rectangle(); <- Should I do that or i...
I'm using MiGLayout and being the freak i am, i was thinking if it's possible to create a single instance of the layout and use it for all my panels? Just curious...
...
I am trying to change title bar color.but it dosen't work
UIManager.put("JFrame.activeCaption", new javax.swing.plaf.ColorUIResource( Color.GREEN));
JFrame.setDefaultLookAndFeelDecorated(true);
...
I am using the following code,
UIManager.put("JFrame.activeTitleBackground", Color.red);
for change the toolbar color in JFrame. But it didn't work.
Is it possible to change the color of titlebar in JFrame?
...
I need to customize my jTable. All I need, is to put a custom Swing object (like jButon, jPanel, etc.) into the table cell. Is it possible? I'm trying:
jTable.getModel.setValueAt(jPanel1,0,0)
and
jTable.getModel.setValueAt(jPanel1.getUI(),0,0)
But the result is only a some kind of string, representing the object...
I'm aware of c...
I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon.
public void mouseClicked(MouseEvent e) {
polygon.addPoint(e.getX(), e.getY());
repaint();
}
But I don't know if this is the best way to draw custom shapes.
It should be possible to edi...
I am trying to implement a JScrollPane with a JTextArea. The JTextArea is being appended to, and I want the JScrollPane to keep scrolling down as more text is added. How can this be achieved?
...
Can I do this without reference to the object in the constructor?
In other words, any class inherited from FrmTaoChild when creating must to add the button on the toolbar of the main window
public class FrmTaoMain extends JFrame {
JToolBar tbTask = new JToolBar();
public FrmTaoMain(String Caption) {
super(Caption);
...
...
private JButton btnTask = new JButton();
...
TaoGlobal.taskbar.add(btnTask);
How to remove btnTask from JToolBar?
Thanx.
...
I am programming a GUI application in Java. I do it for the first time.
I would like to have a form (with radio buttons and so on). After the form is filled in and the "Submit" button is pressed I would like to have a new window. I see two potential ways to do it:
Close the "old" window and open a "new" one.
Remove "old" elements from...
I would like to have a red filled circle at some place in my window. After the click on the circle, the circle should jump from the original place to a new one (disappear from the old place and appear on the new one). What would be the best way to do it?
I also would like to know how to draw a filled circle in Java. Are there any simple...
Hi,
I have the following code:
public class Test extends JFrame implements ActionListener{
private static final Color TRANSP_WHITE = new Color(new Float(1), new Float(1), new Float(1), new Float(0.5));
private static final Color TRANSP_RED = new Color(new Float(1), new Float(0), new Float(0), new Float(0.1));
private static fina...
Bellow is the code for the simplest GUI countdown. Can the same be done in a shorter and more elegant way with the usage of the Swing timer?
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class CountdownNew {
static JLabel label;
// Method which defines the appearance of the wi...
I'm trying to "future-proof" an application that I'm writing by splitting out those elements that are likely to change over time. In my application I need to be able to adapt to changes in the output format (e.g. today I output to a CSV file, in the future I may need to output directly to a SQL Server database, or to a web service, etc.)...
I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it?
I tried the following:
public static void showGUI() {
JFrame frame = new JFrame("Colored Trails");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(partnerSelectionPanel);
frame.setSize(600,400);
...
Hi,
The code I am using is:
public class Test extends JFrame implements ActionListener {
private static final Color TRANSP_WHITE =
new Color(new Float(1), new Float(1), new Float(1), new Float(0.5));
private static final Color TRANSP_RED =
new Color(new Float(1), new Float(0), new Float(0), new Float(0.1));
...
I've got a JTextArea which has the following text "Text1 Text2 Text3".
Is there a way I can make all of them different fonts? E.g. "Text1" is bold, "Text2" is italic and "Text3" is normal?
I know I can create a Font object, however I can only apply it the JTextArea object.
Thanks.
...
Hi all,
I am trying to understand the mechanism of org.jdesktop.swingx.BackgroundWorker. Their javadoc presents following example:
final JLabel label;
class MeaningOfLifeFinder implements BackgroundListener {
public void doInBackground(BackgroundEvent evt) {
String meaningOfLife = findTheMeaningOfLife();
...