How to determine the rotation component?

I have a problem.

I am working on a different guy code, and there is a JFrame with a lot of JSeparators (he used them as borders for β€œpanels”), now I am replacing them with the JBorderedPanel class that follows the same border style of the whole application.

The problem is that some of its delimiters are not clear, to determine where they are in the code, there is a lot of jSeparator #, replace with any number from 0 to 999.

Is there a way to determine which variable corresponds to which boundary, besides testing all jSeparators one by one?

In the section "Do not replace them!". I must replace them. I would not do this if I could.

Thanks in advance.

+3
source share
7 answers

Check out the Swing Explorer . This is a pretty handy debugging tool from swing. There is a plugin for Eclipse that will manage your code on the fly and run it.

With it, you can view the hierarchy of swing objects, right-click on it and display any part of it in another window, which selects each component and allows you to see their boundaries, as well as select them. After selecting, you can right-click the component in the tree and print a stack that will lead you to where this component will be created ...

+8
source

You can add color to each of these delimiters in the code (green, red, yellow, etc.) and see where those colored JSeparators ultimately appear in your application ...

+2
source

Swipe the children of the JFrame and add a mouse listener to each JSeparator inside it:

public void installListeners (java.awt.Container parent) { for (Component child: parent.getComponents()) { if (child instanceof JSeparator) { child.addMouseListener (... hover(event); } } if (child instanceof java.awt.Container) { installListeners ((java.awt.Container)child); } } } 

Now we implement hover() to compare the source of the event with all the fields of the current class and print the one that matches:

 public void hover (MouseEvent event) { for (Field f: getClass().getFields()) { if (f.get(this) == event.getSource()) { System.out.println(f.getname()); break; } } } 

You will have to handle the bazillion from the Exception, but basically that.

+2
source

You can install MouseListener for each JSeparator . When the mouse enters its area, turn it in red and print a line identifying the object, preferably by printing its variable name. This probably requires you to change the constructor calls, but your development environment should support you.

+1
source

I guess the previous guy used some kind of GUI editor.

My first attempt is a graphical editor in Netbeans or Eclipse. They can analyze and display them correctly if the code is not really ugly.

If it can be opened, you can trace where they are by selecting them in the user interface.

0
source

Here, I liked both of your ideas, but all jSeparators are initialized as follows:

 public JSeparator getJSeparatorArvore01() { if (jSeparatorArvore01 == null) { jSeparatorArvore01 = new JSeparator(); jSeparatorArvore01.setLocation(new Point(14, 38)); jSeparatorArvore01.setSize(new Dimension(72, 10)); } return jSeparatorArvore01; } 

How to add mouse listeners (or different colors) to more than 50 jSeparators without spending 24h? : (

0
source

I would advise you not to use borders a lot. Borders are probably the most commonly used component in GUI history. It was originally intended to combine a very small set of related components, usually checkboxes or radio buttons. Then someone sketched the title border, and it turned into a lazy programmer, a way to name sections, which ideally should be done using a shortcut and a space.

The border will simply add visual noise instead of the intended separation. Less - more.

0
source

All Articles