swing

Making a component less sensitive to Dragging in Swing

A JComponent of mine is firing a mouseDragged event too vigorously. When the user is trying to click, it interprets is as a drag even if the mouse has only moved 1 pixel. How would I add a rule for a particular component that amounted to: Do not consider it a drag event unless the mouse has moved 10 pixels from the point at whi...

Java: Accounting for taskbars/menubars/etc when placing a window on the desktop?

When my program starts, the main window places itself where it was when it was last closed. I want to modify this behavior some so if the window is off-screen (or partially off-screen) it moves itself to fully on screen. I've got this working perfectly. Here's the code: int x = gameConfig.windowX; int y = gameConfig.windowY; int...

please recommend a swing book about custom JComponent creation

Please recommend a Swing book that covers creating custom JComponents. ...

Moving focus from JTextArea using tab key

Hi guys, As stated, I want to change the default TAB behaviour within a JTextArea (so that it acts like a JTextField or similar component) Here's the event action private void diagInputKeyPressed(java.awt.event.KeyEvent evt) { if(evt.KEY_PRESSED == java.awt.event.KeyEvent.VK_TAB) { actionInput.transferFocus(); } } ...

How to add hyperlink in JLabel

Which is the best way to add a hyperlink in jLabel? I can get the view using html tags, but how to open the browser when the user clicks on it? ...

How can I remove a column from a JTable with dragging?

In Outlook I can remove a table column if I drag the column header out of the table. How can I do the same in Java with a Swing JTable? A default drag & drop operation is not possible because this feature is independent of the target position. It depends only from the drag source. ...

2 input fields displaying the same thing

Hi guys, Bit of a strange one. I want to have a JTextField, in which the user will type a string. While typing, however, I'd like that text to automatically print to another JTextField in real time. I'm not sure if this is possible because I can't recall seeing any application do it. Anyone even seen anything like this before? Actua...

Post a KeyEvent to the focused component

What is the best way to post a Button Press to a component? I tried using the Robot class and it works, normally. However, this class has some problems under some Linux platforms, so I wonder what is the best Java-only way to post an event to a component. In this particular case, I want to post backspace events to a JTextField when I ...

How to actually use Swing Application Framework?

Hello, I'd like to learn how to effectively use Swing Application Framework. Most of the the examples I've found are blog entries that just explain how to great it is to extend SingleFrameApplication and override its startup method, but that's about it. Sun's article is almost two years old, as is the project's own introduction, and the...

Extra button on title bar for Swing GTK L&F

Hi, Anyone know of anyway to add an extra button next to the general maximize, minimize, restore, and close button on the title bar in Swing GTK L&F? Thanks much. ...

Java simple String diff util

Hi, I'm looking for a simple java lib/src to highlight differences between two Strings, case-sensitive. A html output would be great, but I would be happy to get the indexes of the diffs, something like: diff("abcd","aacd") > [2,2] diff("maniac", "brainiac") > ["man",brain"] or [0,3] or something like that The idea is to higlight ty...

Java GUI Problems

I'm designing a really simple GUI but without any luck. Basically the outer layout has two columns which is a splitter pane (this is for an IRC client I'm writing). On the left-hand side is the server/channel/user tree and on the right is the chat pane. Now I break this down so on the right-hand side there's the output pane at the top...

java swing - layout oddness when using different layout managers

Bit of oddness, seen if I do the following: import javax.swing.*; public class FunkyButtonLayout { public static void main(String[] args) { JFrame frame = new JFrame(""); JPanel j0 = new JPanel(); // j0 gets added to the root pane j0.setLayout(null); JPanel j1 = new JPanel(); // j1 gets added ...

Java's AWT or Swing for GUI construction?

I need to compose a fairly simple GUI for a server monitoring process. It will have a few tabs which lead to a log tailing, counts of resources, and a start and top control. Nothing fancy here. Which Java framework, AWT or Swing, makes more sense for something this simple. ...

How can I make JOptionPane dialogs show up as a task on the taskbar?

Edit: The question follows the horizontal rule; my own answer precedes it. Based on help from Oscar Reyes, I crafted this solution: import javax.swing.JOptionPane; import javax.swing.JFrame; public class MyApp extends JFrame { public static void main(String [] args) { new MyApp(); } public MyApp() { sup...

GroupLayout: Is it worth learning?

I'm relatively new to java (specifically swing) and have recently been making some fairly simple applications, learning as I go. The latest one has lots of form components such as JLabels, JTextFields, JButtons, etc etc. All were placed in NetBeans using a visual builder. I have to say I'm not really taking to NetBeans and have really ju...

Making cut/replace methods with JTextArea

I am to make a cut and a replace method on JTextArea. I have the code for copy and paste, and I reckon I could just use that, in addition to just deleting the marked text in the JTA. How would the code for a code for cut and replace methods look like? The code for copy looks like this: public void copy(){ int start=ta.getSelection...

Adding JTextField to a JPanel and showing them

I'm building a little app using Java and Swing in NetBeans. Using NetBeans design window, I created a JFrame with a JPanel inside. Now I want to dynamically add some jTextFields to the JPanel. I wrote something like that: Vector textFieldsVector = new Vector(); JTextField tf; int i = 0; while (i < 3) { tf = new JTextField(); te...

java swing : custom everything - subclass jcomponent or jpanel or ... ?

Hiya - quick one - is there any harm / value in subclassing JComponent as compared to JPanel ? To me they pretty much look to be the same thing if I'm doing my own drawing & the object won't have any children, however there seems to be a pref for subclassing JPanel over JComponent - just looking for opinions on why this might be ... T...

Change the owner of a JDialog

I have a very specific problem, and I wanted to know if there is a way to change the owner of a JDialog (it can be set using the constructor). I suppose there is no "official" possibility (other than a hack), but I wanted to make sure I didn't miss something. Any ideas or hints on the topic would be helpful, thanks already... ...