Can JTable be resized by the user dragging the mouse - java

So I am creating a GUI and it has a JTable that is set inside of a JScrollpane. When the user opens the window it displays everything how I want it to. The user can add rows to the table to fill in data and then they can scroll through the information. I also have a JButton which I have set to print the whole window. Now my problem is the table prints but only shows the data in the viewing area. What i was thinking was if the user could drag the bottom corner of the JTable to re size it to show everything then everything would be ok, I'm just not sure if that's even possible or how to do it. Ive been searching and i haven't seem to come across anything like this yet.
Edit:
So for anyone else here is the link to the class I found. It allows you to use the mouse to resize any component.
http://tips4java.wordpress.com/2009/09/13/resizing-components/

To get an image of the entire table you can try using Screen Image, which allows you to take an image of a specific component.

Related

.How can I spread my text over multiple jtextpanes?

I´m building a simple word-editor in java. Currently, everything´s working fine. Now I want to create "Pages", like in word. The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it. With a scrollbar I would be able to scroll between them. So far this wouldn't be problematic. However, all the pages should belong to a single document, and if I were to delete a line on let´s say page 2, every line on every other page will be moved up. (For example) Is there an easy way to do this, or will I have to create DocumentListeners for each JTextPane, changing everything on each change? Also, is there a way to extend selections over multiple pages?
Personally I havn't tried anything as of yet, since I want some tips before writing myself into a corner. I thought that I could make the pages uneditable, and instead use a caretListener to check the position the user clicks on, to edit an invisible infinite JTextPane containing the actual document, which would write it´s content to the visible pages.
Lots of unknowns, but maybe the following will give you something to think about.
all the pages should belong to a single document,
Agreed.
The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it
Maybe add each text pane to a JScrollPane, but don't display the scrollbars or Border of the scroll pane.
if I were to delete a line on let´s say page 2, every line on every other page will be moved up
You would need to manually control the viewport of each scroll pane. The first page would position the viewport at offset 0. The next page would position the viewport at the offset that represents your page height.
Then any changes to the Document should be automatically reflected in all the text panes.
You would also probably need to use setAutoScrolls(false) to prevent the viewport from scrolling as you drag the mouse.
is there a way to extend selections over multiple pages?
Selection is a property of the text pane, not the Document.
Not sure what will happen as you try to drag the mouse from one text pane to another.
I'm guessing you might need some special logic. Maybe using mouseEntered/Exited events to trigger this type of processing.

Setting Background Color for single Cells in a JTable through clicking them

I need your help guys.
I am currently working on a simple JTable in Java with 3 Columns and 128 rows. Now there is one problem i cannot solve at the moment. The thing i want is that when I click on a single cell it changes its background color to Green.
So i need to implement a MouseListener which reacts to the selected cell and sets its background to green. Sort of a "CellListener" I mean.
I've tried so many things and searched many blogs etc. but none of them gave me a satisying answer.
Do you have any tips for me?
I doubt you will find a direct link between you being able to click on the table and it respond. Because JTables aren't going to listen out for it like that. If you want to do this. You will need an intermediate step. I would suggest that you use the mouse listener to get the mouse location on the screen when the user clicks. And then check IF that location is the same as a particular cell of the JTable.

Printing a JPanel with a JTable and JTextField

I want to print a Jpanel with two things in it.
I have a Jtable that could have as many as 500 row in it, and I need to be able to print all of them.
I have a JTextfield under the JTable in the JPanel.
I want to print both of these at the same time. The problem I am having is when I print the jtable it only prints the visible part. What I really care about is the content of the JTable and not the Table itself.
Edit: I use Netbeans to build my Gui so I don't really know how to display the code for the Panel, Table, and TextFields.
Here is a picture of the frame everything is in:
The table can have more rows than you can see at once. All the items here except for the button are in a Jpanel, so I need to print this jpanel. What I have found and tried doesn't print all of the jtable, just what is visible to the user.
When you call table.print() it will offer a dialog and you click print. I can't help you more until you post some code but this works for me.

How to change the image by click keyboard arrows?

I have made one project in java. Now in this particular module, i am showing the user , so i am showing them a stock inventory.
Now for doing this.
As you will see in the screen shot [ i have put screenshot so you can understand well ].
To show the images , i have made one table and i have put labels in that and then i am setting the icon at the label.
Now as soon as user click on the any image, then that image i put on big label.
But this works perfect on mouse click but client want that , if user navigate the by keyboard arrow keys then in same should be happen.
Means : User navigate by key board then it should reflect on that table [user should know that which is currently seleted ] and then as soon as the user navigate by key board arrow events and then click enter then that image should reflect on big label.
Here is the Link for that screenshot.
Sounds like there are two steps in what you need to do.
First, the user needs to know which image is selected. Unfortunately I can't help you with that, since I don't know how you're displaying that grid. From a UI point of view, I'd suggest exploiting that white border you've got in each cell -- change it black, blue, or whatever color you like to indicate that it's the selected cell. You seem to be using a JTable, in which case you can write a TableCellRenderer (probably by extending DefaultTableCellRenderer) and call its setBackground() method.
Then you need to listen for keyboard input. This part shouldn't be too bad; write a KeyListener and add it to the JTable itself. For each key event, see if the key code matches the arrow keys; if so, move your cursor around accordingly. Don't forget to watch out for the edges of the JTable.

jList in Scrollpane, seeking and displaying value of selectedIndex

I have a JList inside a Scrollpane. If you click on the list and move the arrow keys up and down it works like you expect, you can move your selection index and display around just fine.
Now, what I want to do is basically have a text box and i'm typing in the text box like "comic" and want it to seek to the index of that value. This WORKS just fine.
Where the problem is when the value of the list box is below, or above the viewable area. When it is, the selected index seeks, but does not change the position of the scrollable region. However, if I press the up or down arrows and requestFocus() to the list, and move up and down it seeks to the right viewable area.
What am I missing to make this happen WITHOUT changing focus. I want to be able to just type in the list all I want and have it show me what is selected. I feel i'm missing something obvious here.
If I understand the question then you should be able to use:
list.setSelectedIndex(...);
list.ensureIndexIsVisible(...);
If that doesn't help then post your SSCCE demonstrating the problem.

Categories

Resources