JScrollPane mouse-wheel area - java

I have a JScrollPane and a JPanel inside. I see the scrollbars when needed, but the mouse wheeling works only when the mouse is over the scrollbars. Is there a property or something to make mouse wheeling work when the mouse pointer is over the whole panel, not just the scrollbars? You know like in browsers - you can scroll the page even if the mouse pointer is not over the scrollbars.
Thanks in advance!

It works for me (Java 6, Windows, JScrollPane containing a JPanel, mouse wheeling over JPanel). JPanel with rounded 100 pixel borders, min size 1000x1000, preferred size (4000x4000).
So I guess, that your existing code interferes. Try a separate example, and then rework your app.

Make sure main window(possibly a JFrame) implements Scrollable.

Related

Set JFrame's components' size relative to window size

I have a resizable JFrame and (since I do not know much about Layouts yet) set its JPanel Layout to null.
Is there a way I can tell my program to resize each of its components' size relative to the window's size?
e.g. I have a 200x100 default sized JFrame, on which a button is 20x10. If I resize the window to 400x200, I want the button to be (still on the same position relative to the window's edges) resized to 40x20.
If that works is there a way to do the same thing with fonts? E.g. size 11 on 200x100 but something like size 14 on 400x200.
Regardless of what convention you use to scale your components and font, it is not a good idea to set a layout to null. Widgets behaving strangely when using "setlayout(null)" will give insight to why this is error prone. Automatically size JPanel inside JFrame might help with scaling when you change the size of the JFrame manually.
Add a ComponentListener to your frame and create a table with the defaultSizes of the Components for a specific windowsize. The componentResized(ComponentEvent e) will be called each time the window is resized. Inside it, you can resize the components. Or you implement your own LayoutManager.

How to make a JFrame scrollable?

I would like to scroll through the contents of my JFrame up and down, preferably with a scroll bar. I don't want to wrap the contents inside a JPanel or JScrollPane, because this causes some visual glitches with my application.
Any idea on how to do this?
JScrollPane would be the easiest way; you say there are glitches, but that probably indicates a problem in your code that will still be a problem even without using a JScrollPane.
If you're absolutely set on not using a JScrollPane, you should create a JPanel using BorderLayout, add a JPanel (call it 'center') with BorderLayout.CENTER and layout set to null. Add your content within 'center', and add another JScrollBar to BorderLayout.EAST, add an AdjustmentListener to the JScrollBar. When the adjustmentListener triggers, you need to move your content (Component.setLocation(...)) that's in center to the relative y offset of the JScrollBar and call repaint on 'center'

Making JFrame transparent breaks scrolling on Mac

I have a transparent undecorated JFrame that I set using AWTUtilities.setWindowOpaque(this, false). On the JFrame, I have a scrollpane; it works perfectly on Windows. On the Mac, the whole JFrame is draggable; so when I try to scroll through the scrollpane by clicking and holding the mouse on the scrollbar, the entire frame moves instead of the scrollbar thumb. I also tried to use setBackground(new Color(0,0,0,0)) instead of setWindowOpaque(), but it has the same problem. Any ideas on how to fix this?
As suggested in this similar thread, try:
getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);
If you choose to use this, the scrollbar will be usable and the window won't drag. However, you may be stuck with an immovable window, unless you add a MouseMotionListener and move the window around in the mouseDragged() method using a call like frame.setLocation().
Instead, you might be able to force the user to click on the scrollbar's arrow buttons, rather than drag the scrollbar itself... But that's not the most user-friendly idea I've ever seen.

How do I limit vertical JDialog resizing to a single component within the dialog?

I have a JDialog that consists of two JPanels, one above the other. Currently, when I resize the JDialog only the bottom panel resizes in the vertical direction. However, I only want the top panel to resize. The only component that the top panel contains is a JScrollPane, so I want any vertical resizing to result in an increased/decreased view of the top panel's content. What is a good way to do this?
Thanks in advance!
elise
, I only want the top panel to resize
dialog.add(topPanel, BorderLayout.CENTER);
dialog.add(anotherPanel, BorderLayout.SOUTH);
This is a job for the proper LayoutManger. Here is a good link that explains LayoutManagers visually and does it quite well.

Java Swing JPanel Stay on top of JTable

I have a Jpanel that is used for displaying messages. When mouse enters a JLabel it expands to normal size and when mourse leaves it disappear.
There are overlaps between JTable and JPanel when the JPanel expands to normal size. As JTable's height cannot be changed during runtime only way I can think of is let JPanel stay on top of JTable.
I am very new to Java ans swing. Any idea please?
Sound like you should be using a tool tip.
Edit:
Try using a BorderLayout. Add your main panel to the CENTER and your message panel to the SOUTH. When you make the message panel visible you can revalidate() the main panel and the Center panel will shrink in size to take whatever space is not required by the south panel.

Categories