swing

Swing: Scroll to bottom of JScrollPane, conditional on current viewport location

Hi all, I am attempting to mimic the functionality of Adium and most other chat clients I've seen, wherein the scrollbars advance to the bottom when new messages come in, but only if you're already there. In other words, if you've scrolled a few lines up and are reading, when a new message comes in it won't jump your position to the bo...

Java Stopping JApplet Components from Resizing based on Applet Size

Creating a JApplet I have 2 Text Fields, a button and a Text Area. private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3)); private JPanel outputPanel = new JPanel(new GridLayout(1,1)); private JTextField serverTf = new JTextField(""); private JTextField pageTf = new JTextField(""); private JTextArea outputTa = new JTextArea(...

Mixed alignment with Java Swing's GroupLayout

I'm trying to build a GUI window in my application. What I'm trying to do is have a window, with a few buttons at the top, and a large text area. Something like this: +--------------------------------------------------+ | [button1] [button2] [button3] | | +----------------------------------------------+ | | | text a...

Java-Swing: Change getSource() in ActionListener

I have a class that contains a JButton. This can't be changed. The problem is this: The actionListener calls getSource() and gets the JButton, not the container class. Can I change what getSource retrieves, before the actionListener is added? OR can JButtons have a variable reference to its container? I can't make a class extend a JBu...

How to LIMIT the text box length?

I am working on eclipse java using swt jface with rcp. How can i limit the characters in my text box. Like if i want only 4 characters in my text box then what should i do? and what if i want alphanumeric combination . again in certain limit? ...

Multi-value JSlider component?

I need a multi-value JSlider (or a similar component) for an analysis application. The two features missing from the regular JSlider are the ability to have more than one knob and also the ability to add or remove knobs on the fly. The reason for this is that they will be used to partition the 0..100% range for a particular factor into t...

Trouble getting Swing to refresh JLabel (apparently on event dispatch thread)

I have this action listener: this.newGameButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent a) { MokkiGUI.this.game = newGameQuery(); MokkiGUI.this.AI = new AIPlayer(MokkiGUI.this.game.getBoard()); MokkiGUI.this.boardLabel.setText(""); MokkiGUI.this.boardLabel.repaint(); refresh...

jtabbedpane different sized tabs

hi, im making a search function for a database that uses a jtabbedpane with one tab for a quick search, and one for an advanced search. the advanced search has quite a few more fields, so it needs to be larger, but i dont want the whole window to always be at the largest size for aesthetic reasons. i have added a change listener to the p...

Java Refreshing a screen

I have a screen in which one of its components is made invisible depending on a boolean value. If the boolean changes after the screen has been created, how do I refresh the screen to take this into account? ...

How do I keep a dialog box always on top?

I created a dialog box like this: String response = JOptionPane.showInputDialog(null,"message","title",JOptionPane.PLAIN_MESSAGE); I'd like to keep it always on top of all windows. Do you have any idea? Thanks! ...

How to Stich to Image objects in Java

Hi, I have a scenario in which i`m getting a number of tiles (e.g.12) from my mapping server. Now for buffering and offline functions I need to join them all back again so that we have to deal with 1 single image object instead of 12. I ve tried to do it without JAI my code is below. package imagemerge; import java.awt.*; import java...

Check if thread is EDT is necessary?

Hello, I have an UI implemented with Swing. One component does some work that may take some time, so I use SwingUtilities.invokeLater. However, I was reading some old code and found this in an ActionListener: if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { public void run() { ...

Scrollbars on JTextArea in a JScrollPane do not work

Hello, I'm having trouble getting a JTextArea to scroll. I'm not sure how you can mess up a JScrollPane but I seem to have and I just can't see it. It's all part of a larger project but the code below is how I'm creating a JTextArea and adding it to a JScrollPane. When you type beyond the edge of the text area the scrollbar doesn't appe...

Get object location Java2D (not corner).

How do I get JLabel location instead of top left x/y location of the object in Java? ...

Java2D Distance Collision Detection

My current setup is only useful once collision has been made; obviously there has to be something better than this? public boolean CollisionCheck(Rectangle rect1, Rectangle rect2) { if(rect1.intersects(rect2)) { return true; } return false; } How can I do preemptive collision detection? ...

How can I rotate an image using Java/Swing and then set its origin to 0,0?

I'm able to rotate an image that has been added to a JLabel. The only problem is that if the height and width are not equal, the rotated image will no longer appear at the JLabel's origin (0,0). Here's what I'm doing. I've also tried using AffineTransform and rotating the image itself, but with the same results. Graphics2D g2d = (Gra...

Java Swing Table questions

Hey guys, working on an event calendar. I'm having some trouble getting my column heads to display.. here is the code private JTable calendarTable; private DefaultTableModel calendarTableModel; final private String [] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", ...

Java swing JLabel not showing

On exiting my game, I would like to show an "exitscreen". The exitscreen.gif is in the folder, and works fine, but for some reason, only the blank frame shows with this: JPanel finishPanel = new JPanel(); JLabel finishLabel = new JLabel(new ImageIcon("welcomescreen.gif")); finishPanel.add(finishLabel); finishLabel.setSize(11 * 35, 11 * ...

How to get Java swing application to respect OS DPI settings

Is there a way to set DPI in swing ? For the whole application ? And if there is how do I set it to the value of system DPI ? I guess there must be a way to do it as I mentioned this feature must have benn added to NetBeans in some of latest versions... Thank you for reading ...

How do I get a JComponent to resize after calling `setVisible(true)`?

Our application displays a 2D view of our data (mainly maps) and then allows the user to change to a 3D view. The 2D and 3D views are generated by custom C++ code that is SWIG'ed into our Swing GUI and wrapped within a JComponent. These JComponents are then displayed within another parent JComponent. Our problem is that when we change f...