JScrollPane: Disable Scroll-by-dragging - java

I am using some JGraphX components but this question can be applied to a general purpose of java.
I have a component inside of a JScrollPane. The issue I am having is that I have the ability to pan in the view by "grabbing" the view and moving it around like Google maps. but if the cursor leaves the viewport the scrolling changes directions. I have done some research and found the issue causing the problem. It can be found part of the way down on this page where it starts talking about how the scrollpane works.
http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html
Move the cursor over the image and press the cursor. Continuing to
press the cursor, drag to a point outside the image and pause. The
visible area of the image moves toward the cursor. This
scroll-by-dragging functionality is enabled by the scroll pane, and
with the JComponent API, but it is implemented by the custom component
that displays the image.
It has the little demo so you can see how it works as well as the code is available for download.
So by default the scrollpane has a scroll to drag implemented but it is actually opposite of how I need mine to scroll. The JGraphX library I am using has extended most of the classes used to benefit itself in some way but the basic idea still applies. I really just need to know of the easiest way to disable this. Yhe page says its enabled by the scrollpane and the JComponent API, but what actually gets enabled?

Not sure but I think you need to use:
component.setAutoscrolls( false );

This method from JComponent looks like the best starting point to investigate. You could retrieve the component in your scroll pane and call that method with false on it. That's the default, but it's possible JGraphX has it enabled by default.
Alternatively, you could get the MouseListeners and/or MouseMotionListeners from the scroll pane and replace them with something that overrides the dragging behaviour. Since those are interfaces, you could use proxy objects for that. Seems somewhat hacky, though.

Related

Synthetica JButton Margins

So, I have a Calendar solution for my employers where I am using a custom look and feel (Synthetica) and each cell in the table holds a JPanel with a list of buttons and a PAGE_AXIS BoxLayout. I am trying to reduce the gaps between each button so that they abut each other, and I've tried setting the borders to null except that destroys the button appearance. I have used the following (as recommended by Oracle to view the actual size of the components) code;
setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.red),
getBorder()));
And this is what I get;
Setting the margin does not work with whatever border version the buttons are using. So, is there any way to find the current border that it's using? So that I can set that border's insets manually, or something like that. Basically, I need the buttons to abut each other. Any ideas?
Clarification: I want the button's themselves to stay the same size, but I want the white space around them (highlighted inside of the red borders) to be gone,
Several possibilities should be considered:
Manipulate the button's bound properties: setBorderPainted(false), et al., as suggested here.
See if a suitable sizeVariant is available, as shown here.
Use a custom UI delegate based on BasicButtonUI, as shown here and here.
I tried to get the Synthetica L&F to have a look but seems as though you have to create an account which I did not want to do. Anyways, a quick look around the website and I found a page which indicates how you can see and configure some of the values set in the L&F. Might be worth having a look there.
http://www.jyloo.com/synthetica/customize/

jscrollbar show other components

Good evening everyone;
I java swing i am trying to have a menu like in the picture
(in the picture left side)
However, it appears that it is more difficult than i thought.I had border layout and i put box layout in the middle and jscroll bar for the right side. Inside the box layout i but labels with icons and i try to chance visibility with adjustment level event. However, i could not manage to obtain any results. I made a research on the internet and stackoverflow however, again i could not exactly reach my purpose.
Regards ...
JScrollBars are not typically used alone, they are used in conjunction with JScrollPane.
Basically, you want to add you components to a container of some kind (say a JPanel) with an appropriate layout manager, then set that container as the view within a JScrollPane
See How to Use Scroll Panes for more details
i found an answer inspiring from comments of other users. First of all thank you for having a look to my question.
i used the codes in here;
http://www.java2s.com/Code/Java/Swing-JFC/AsimpleJScrollPanedemonstration.htm
problem is i required to create a container and put the items to container and then take that pane to put jscroolpane.
Regards ...

Swing JCheckbox: Focus with customized icons

I've used
chkBox.setIcon();
chkBox.setSelectedIcon();
chkBox.setDisabledIcon();
chkBox.setDisabledSelectedIcon();
to set custom icons for my JCheckbox. But now, if the focus moves to one of the checkboxes, there is no border shown around them or anything else, which tells that the checkbox has focus.
Does anyone know, how to give some feedback when a customized checkbox has focus?
Thanks
Your problem definitely depends on Look and Feel (L&F) that you are using in your application (if you don't setup one - i guess you are using MetalLookAndFeel?).
Anyway, there might be a lot of solutions:
Check that your JCheckBox is actually focusable and focus painted. Be aware that some L&F might switch off focus painting - check checkBox.setFocusPainted() method.
If you are not satisfied with default focus painting - you might want to create your own CheckBoxUI that paints a better focus indicator. That requires some basic knowledge in UIs creation though.
If you want to paint focus indication straight on the check icon itself you can create your own Icon-based implementation that paints it together with current check state. I have posted a custom Icon example in other topic about state-dependant icon if you want to see a real example.
There might be other solutions but they depends on the L&F you are using...
You can use this ready-to use checkbox alternative:
http://codetoearn.blogspot.com/2013/01/swing-fantasy-checkbox-with-customized.html

Component for glass pane console-style text display

I'm trying to provide a progress report for a slow operation, in the form of text scrolling up from the bottom of the screen with details on what's going on - it's an effect you may have seen a few times in video games when they're loading maps, making network connections and suchlike.
Glass pane seems to be the way to get the text overlay, that much I have working. My problem is exactly what component to use for the actual text display.
JTextArea can display text, but as far as I can see, it can only do it from the top of the screen down - is there a way to make it scroll text up from the bottom of the screen?
JLabel by contrast can align the first line of text to the bottom of the screen, and even take appended text on that line, but when I add more lines separated by newline characters, it just seems to swallow them up even after calling repaint and validate. Is there a way to make it scroll up with the new text?
Or is there another component I should be using instead?
I really like JXLayer for effects layered over Swing components. JXLayer was at one point scheduled to be included in Java 7. Unfortunately the moving around that has been going on Java.net lost all the good content that the author had. There are still some other great resources around (Java 7 required for this one) on the web. I use JXLayer to provide panels with a busy state having a web-like spinner and greyed out appearance.
Another alternative (not as capable as JXLayer IMHO) is MigLayout has absolute positioning, which is maybe easier than the GlassPane.
JLabel would be the easiest. Otherwise you will have to override paintComponent to do anything fancy like animating the text movement.

Render Newly Visible Portion Upon Scrolling on JScrollPane

I have a large JPanel embedded in a JScrollPane. When I move the scrollbar, I notice that the visible portion does not render itself and I get glitches. Whereas when I resize the frame, I can see the new visible portions rendered. So I need to know which methods are fired upon frame resize to repaint the view. What listeners/methods should I use?
So I need to know which methods are fired upon frame resize
You don't need to know that. All you need to do is change the value of the scrollbar or the position of viewport and the component should repaint itself properly. If it is not painting properly, then you have a problem with something else. Maybe
incorrect custom painting code
the code is not invoked on the EDT
If those suggestsion doen't help then you need to post a proper SSCCE that demonstrates the problem because we can't keep guessing what your code is doing.
Did you revalidate the panel?
It might be that something is not right in the code of yours.
I have been using lots of scrolls and never had an issue as you describe.
Maybe a code sample showing the problem would be nice.
Good luck, Boro

Categories