swing

How do I move a Java JFrame partially off my Linux desktop?

I'm writing a Java application with movable frames, and I've come across a quirk in Linux. I'm running GNOME 2.16.0 under CentOS. When I use JFrame.setBounds to set the bounds to any location that's half off the screen, it actually sets the location of the frame to be as close as possible to the bounds specified while still staying com...

scala for yield setting a value

Hi, I want to create a list of GridBagPanel.Constraints. I read it in the scala programming book, that there is a cool for-yield construction, but I probably haven't understood the way it works correctly, because my code doesn't compile. Here it is: val d = for { i <- 0 until 4 j <- 0 until 4 } yi...

How to make JPopupMenu not take focus/mouse cursor?

Hello, I show() a JPopupMenu based on what the user types in a JTextField, however, when that happens the user typing on the keyboard will no longer write into the text field, unless with the mouse clicks again on the field, thus closing the popup menu. I want, like in Eclipse and NetBeans code completion feature, that the user may sti...

How to draw a filled circle in Java?

I have a JPanel with a Grid Layout. In the "cells" of the grid I can put different elements (for example JButtons). There is no problems with that. But now I want to put a filled circle in some of the cells. I also would like to relate an ActionListener with these circles. In more details, if I click the circle it disappears from the cur...

What is a simple way to create a text field (or such) that only allows the user to enter ints/doubles in Java?

I am looking for a way to ensure that my text field (JTextField, JFormattedTextField) is returning a double or int rather than a string when I call .getText(). What is the best way to do this (if possible)? Thanks! badPanda :D ...

Can I add a component to a specific grid cell when a GridLayout is used?

When I set the GridLayout to the JPanel and then add something, it is added subsequently in the "text order" (from left to right, from top to bottom). But I want to add an element to a specific cell (in the i-th row in the j-th column). Is it possible? ...

How to make JTabbedPane autoresize to fit page dimensions?

I have only JTabbedPane inside JFrame. JTabbedPane sets its dimensions to biggest page width/height. As pages has different size is it possible to force JTabbedPane to change its dimensions when selecting other page? http://grab.by/3hIg Top one is how it behave now and bottom one is how i want it to behave (i resized frame by hand) ...

Advice welcomed on creating my own Swing component

Recently I asked which was the best Swing component to bind to a BigDecimal variable (with some particular editing properties). It turns out that none of the standard Swing components suit me completely, nor did the third-party Swing component libraries I've found out there. So I’ve decided to create my own Swing component. Component de...

are scala's mouse events working? how?

Hi, I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work? class Hyperlink extends Label{ text = "hyperlink" reactions += { case MouseClicked(_,_,_,_,_) => println("mouse clicked")}} I put this in some panel and click over the label like a pro minesweeper player... a...

JTable row filters updates

Is there a way to tell a JTable's row filter that it should update itself to display the filtered data? I'm currently using the fireTableDataChanged method in the AbstractTableModel but the underlying data for the table isn't actually changing, so this seems like it might be wasteful. The way my filter works is to check if data in the ta...

Java focus question

This may be a silly question I don't know. Is there a way to remove the highlighter to represent focus in a Java GUI? For example when you click on a button the text will have a slight rectangle around the text. Thank you ...

Why cant i draw an elipse with this code?

package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class test_bmp extends JPanel implements MouseListener,MouseMotionListener,ActionListener { static BufferedImage image; Color color; Point start=new Point(); Point end =new Poi...

JTable and Database in Swing

I need to load database content into a JTable. Many times I search for help. Please anybody can refer a tutorial please, otherwise anybody can help me to do so. ...

JLabel with separate text and icon background colours

Hey, I have a simple Jlabel element with text and icon setting the background changes the full label colour. I want to be able to only render the background colour on the text section of the label, ie - to have separate backgrounds/foregrounds for the icon and text. Selecting/deselecting the label will flip the colour behind the ic...

how to add images to a panel at any location (x,y)

i want to add images or labels with image in it to a panel at any location which will be decided by the user clicking on the panel(add image where user clicks in the panel). how to do this. thanks ...

Help on writing your own javax.swing.text.Document

I'm writing a Java TextComponent where the underlying document has some structure. It is very short, basically one line. I need to be able to override the response to inserting or deleting characters in some parts of the document. My initial approach was to implement javax.swing.text.Document, but this seems to involve developing many a...

Why is getPreferredSize() returning a size that is too small for this JDialog?

In our product, we have frames that are basically three inheritance levels down from what is essentially a JDialog. This frame overrides the default pack() method as shown: @Override public void pack() { this.setSize(getMaximumSize()); validate(); super.pack(); } @Override public Dimension getMaximumSize(){ return supe...

Piano Keys in Swing Layout: Left-Padding?

I am creating a container of JComponents which will look like a piano keyboard. The black keys look like this (Groovy) def setBlackNotes(buttons) { def octaves = (int)(buttons.size() / 5) def gridLayout = new GridLayout(1, octaves*7); def blackNotePanel = new JPanel(gridLayout) this.add blackNotePanel def i = 0 ...

Icon in titledBorder title

Hi is it possible to place an icon in the title of a titledBorder for example the following code: import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.TitledBorder; public class TitledExample extends JPanel { public TitledExample() { super(true); ...

How to use .DefaultListCellRenderer

First, i'm new at Java-programming and my native lang is not english, but still i hope to get some help from you all. What I try to do is a simple java-interface with a jComboBox and a jList. I want to poplate to jComboBox with Object-names and when the user select one of the names get the object-id which i will use to populate the jList...