swing

Dispatch MouseEvent

there is a way to Dispatch MouseEvent , same as dispatchKeyEvent using the KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(listener); that happens before the event transferred to the component ? i know i have 2 options 1) add mouse event to all compoenents recursive 2) use a transparent glasspane dose j...

Can I force automatic wrapping in BorderLayout

I was wondering if it is possible to force components in BorderLayout to wrap like they do in FlowLayout. ...

Best practice for an application with GUI

Hi, I'm about to start an application which will have both console and GUI interfaces. What I wan't to achieve is COMPLETE decoupling of application logic from interface. In future, I may also add web interface, and I don't want to change anything in my application. Is there a good example (perhaps some open source project) where I can...

How do I keep JTextFields in a Java Swing BoxLayout from expanding?

I have a JPanel that looks something like this: JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); ... panel.add(jTextField1); panel.add(Box.createVerticalStrut(10)); panel.add(jButton1); panel.add(Box.createVerticalStrut(30)); panel.add(jTextField2); panel.add(Box.createVerticalStrut(10)); panel.a...

How to draw 'biohazard' with swing

I'm practicing my swing abilities for the upcoming test, and fried gave me idea to draw biohazard sign like this : I could draw the circles with Elipse2D, but then I somehow need to cut those 3 triangles. Any ideas how I can do that ? ...

Drawing star shapes with variable parameters

Hi. I have task to write program allowing users to draw stars, which can differ in size and amount of arms. When I was dealing with basic stars I was doing it with GeneralPath and tables of points : int xPoints[] = { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43 }; int yPoints[] = { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36 }; Graph...

What is the proper way to get the current look-and-feel's component background color in Swing?

I am writing a custom Swing component with my own painting. I'd like to query whether or not the current look and feel's components are opaque, and if so, what their background color is so my component can use it too. I'm having a hard time finding that on Google. Anyone know? Thanks! ...

Domain-driven design in desktop applications

Having used DDD for a web site and finding it to be a neat approach, I'm wondering if this can/should be applied to desktop applications? Also, with the classes being separated into different packages, how could the MVC pattern be mixed in? ...

call transferFocus or requestFocus ?

in my application i get a component to focus , it could be a jpanel , and is could be a jbutton or a user custom made component how can i know when to call transferFosus ,and when to call requestFocus thanks you ...

Restrict number of lines in html JLabel

I have a JLabel that needs to display some html-formatted text. However, I want to restrict this to being 4 lines long (and if so, provide a button to see everything). So far, I've tried setting the maximum size manually or via a layout manager. However, both of these solutions can cause part of a line to be displayed. edit: To add a...

Java application design question

I have a hobby project, which is basically to maintain 'todo' tasks in the way I like. One task can be described as: public class TodoItem { private String subject; private Date dueBy; private Date startBy; private Priority priority; private String category; private Status status; private String notes; } As...

Swapping out the center JPanel in a BorderLayout

I have a JPanel sitting inside the center position of a BorderLayout of a JFrame. How can I swap out the current JPanel for a new one? ...

mig layout - span and grow/push problem

i want 3 components laid out on 2 lines, so that the bottom component and the top-right component use all available horizontal space. JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setLayout(new MigLayout("debug, fill")); Container cp = frame.getContentPane(); cp.add(new JTextField("com...

how to draw pythagoras tree

How to draw pythagoras tree in swing ? http://mathworld.wolfram.com/images/eps-gif/PythagorasTree_825.gif ...

How to listen to JComboBox's width changes?

I tried PropertyChangeListener with property set to "width", "Width", "size" and "Size". PropertyChangeListener widthChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { //code } }; streamsComboBox.addPropertyChangeList...

Make a JButton exactly the same size of its Text

Is it possible to make a JButton take exactly the size of its text? Since by default, a JButton will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that padding. thx ...

How to add clear option to this whiteboard?

i have to add clear screen option to my whiteboard application, usual procedure is to draw a fill rect to the sizeof the image. But in my app i have transparent panels added one above the other i.e as layers, if i follow the usual procedure the drawing from the underlying panel wont be visible. please tell me any logic to do this. publi...

Generic solution to deselect buttons in java

In a set of radio buttons of the same group, only one can be selected at the same time. I would like to have the same behaviour with a normal button. Imagine there's a row of 3 buttons. When a button is selected it changes: but.setSelected(true) and the other two buttons should be NOT selected: but.setSelected(false) Now, is there a ge...

Is it possible to set different look and feel for different panels within a same frame?

Say, I have 3 panels added to a frame and for the 1st panel i want to set the metal look and feel, for the 2nd panel I want windows look and feel, for the third panel it should be default swing style. is it possible? ...

Java Swing - How to disable a JPanel?

I have several JComponents on a JPanel and I want to disable all of those components when I press a Start button. At present, I am disabling all of the components explicitly by component1.setEnabled(false); : : But Is there anyway by which I can disable all of the components at once? I tried to disable the JPanel to which these compo...