Resize JTable in JScrollPane by dragging - java

How can I implement the functionality of being able to resize a JTable by dragging a corner by mouse (to see more rows during a single view) which is embedded in a JScrollPane? Is their any other easy alternative way? Thanks a lot.

Add the JScrollPane to the ComponentResizer class.

Related

JPanel adjust to JScrollpane and children

I'm trying to make a ToDoManager in java. For now I have about what I want it to be for a basic version. But I'm having a problem with the size of a panel.
I have a main JFrame. This contains a JPanel, say jPanel1.
jPanel1 has 2 buttons (add and remove) and another JPanel (say jPanel2).
jPanel2 contains a JScrollPane, which contains a modified version of JTable.
The thing I want is to tell the JTable to stretch out, so i can view everything in the JTable, and then tell the JScrollPane and jPanel2 to "Pack", or resize, so the JTable is completely vissable (if not possible the JScrollPane should do its work and draw the scrollbars).
This is what I have got at the moment:
So maybe you can see 2 problems:
1) The horizontal scroll bar does not appear. (But I did set the scroll bar: HORIZONTAL_AS_NEEDED)
2) I did not set any preferred size for the main JFrame, nor for the jPanel1, but it packs always as the same size. So I would like to stretch the jPanel2 to the full JTable, and if that would exceed the screen size, draw the scroll bars.
Using another layout manager, it's a lot easier to comprehend the usage of the JPanels and this concludes the problem.

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: JScrollPane didn't show scroll bars

I am developing a small desktop application in Java using Netbeans. On my jframe i have various pannels and one scroll panes. The purpose of this JScrollPane is to show some visual elements to its users. I achieve this by following the below steps in sequence:
Drag and drop JScrollPane at desired location of my JFrame
Adjust the size of JScrollPane according to my needs.
Write a new java class and extend that class with JPanel
Override the public void paintComponent(Graphics g) method
Then i add that panel to above JScrollPane,
using following code:
JPanel jpnl = new myClass();
jScrollPane2.setViewportView(jpnl);
jScrollPane2.repaint();
Now every thing is working fine as per my requirements, the only thing which is lacking is that when my drwaing is big then no sroll bars are shown at JScrollPane. This is my first application and i don't know much about Java, so any guidence regarding what is missing would be highly appreciated
Remember to add the required component to the JScrollPane object, and the scroll pane object to the panel. Also, it could be that you need to change the scroll bar policy: use scroll pane's setHorizontalScrollBarPolicy() and setVerticalScrollBarPolicy().
Consult the JScrollPane documentation for these methods.

JScrollPane Movement Restriction Query?

I have JTable of order nxn with the JScrollPane size being
JScrollPane jsc = new JScrollPane(table);
jsc.setPreferredSize(new Dimension(500,700));
The Scenario is this:: whenever I edit the last cell (it contains a JTextField) of the JTable by dragging down the ScrollBar and come out of Focus, the ScrollBar slides back the original position, i.e the beginning position. I would like the ScrollBar be in the place where it was set by the user before and after editing.... how can this be achieved?
Thank You In Advance....
you can able to determine scrollToVisible(JTable table, int rowIndex, int vColIndex), example here
Because JTable is a Scrolling-Savvy Client, it implements the Scrollable interface. You may get better results using the method setPreferredScrollableViewportSize() instead of calling setPreferredSize() directly on the scroll pane.

How do I set Z-order for image in Swing Java

I have 3 image so I want, if I drag any image that should appear above all the other images. Which technique can use? please any idea???? By the way I am using "ImageIcon".
Thanks in advance.
If what you want to do is click on an image, lift it above the others and then drag it, consider placing them in ImageIcons and these in JLabels, and displaying them in a JLayeredPane, or a JPanel that is held in a JLayeredPane. You can then lift the clicked label onto the JLayeredPane.DRAG_LAYER while dragging, and then drop it down into the DEFAULT_LAYER (or on a JPanel that's on the DEFAULT_LAYER) when done. For an example of this, please see my code in a related question: dragging a jlabel around the screen
If I'm totally off base, sorry, but please correct my incorrect assumptions.
By the way I am using "ImageIcon".
I assume this means you are adding in image to a JLabel and are then adding the JLabel to a JPanel.
so I want, if I drag any image that should appear above all the other images
You need to add a MouseListener to the JLabel. When you click on the label then you can reset its Z-Order to 0. This will cause the label to be painted last and so it will be on top of all other labels on the panel.
So the basic code in the MouseListener would be:
panel.setComponentZOrder(label, 0);

Categories