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.
Related
I've been working on a Pokemon-themed quiz game in Java (modeled after Sporcle, if you're familiar). Pretty much everything works how I want it to, except for the layout of the different components of the program.
I've never been very good with the different layout managers, and I don't know how to get them to do what I need.
Here's what the window looks like right now:
Now, I'll play around with font sizes later, but the tables themselves look exactly how I want them to. The problem is, I want them to be under the text fields and buttons and stuff. Here's the portion of the code where I add all the components to my JPanel:
panel.add(label,FlowLayout.LEFT); //adding the "big question text"
panel.add(answerfield); //adding the JTextField
panel.add(correctAnswerTracker); //adding the "x / 151" text
for(int x = sPanes.length-1; x >=0; x--) //as you keep adding to left, it gets pushed over, so doing it backwards results in the correct order
panel.add(sPanes[x],FlowLayout.LEFT);
//each table is in a scrollPane, and all my scrollPanes are in the array sPanes, so I'm looping through that to add the tables
panel.add(startStopButton); //button that says "Start"
panel.add(exit); //button that says "Exit
panel.add(timer); //the timer
As you can see, the statements to add the text field, and correct answer tracker are all written before the add statement for the tables, and yet the tables are at the top. Additionally, there's the issue of my tables in that loop being added in the backwards order, so I had to reverse the direction of the loop iterations to get the tables to appear in the correct order. I've tried using stuff like setLocation and setBounds to get my components more where I want them, but nothing happened. Also, everything just appears in a row below the tables (and I know that's what FlowLayout does), but how would I go about customizing exactly where things appear?
Wrap a panel with BorderLayout around ones with FlowLayout. Put all the content that should be above the tables in a panel and add it with BorderLayout.NORTH. Put all the content that should be below the tables in another panel and add it with BorderLayout.SOUTH. Then put the tables in their own panel just as your are now, and add it with BorderLayout.CENTER.
Either use a LayoutManager or setLayout(null). In the latter case, you can move your components around by calling setBounds on them. I've been doing that lately too (not using a LayoutManager), it's quite liberating.
What I'm trying to achieve is a JTextField with a JTable on the bottom, every time a change occurs on the JTextField (type or delete a character) the JTable would update showing the results from it's list of strings that match what is written on the JTextField, and showing all results if empty.
What I don't know how to do :
How to set the event on the JTextField that triggers everytime its text changes
Making the JTable update its values in an efficient way, without using too much memory
Add a DocumentListener to your JTextField. Update the TableModel belonging to your JTable with matches. The JTable will update itself in response.
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.
I have created general bill maker application on swing in which i've to print receipts as the output.
Basically i am not able to understand how can show the list of items on the panel so that it is able to print?
I am using PrintUtilities.java to print
the receipt panel.
What i am trying is to use a JTable for listing item details but if number of items is more than scrollpane viewport hieght than the rest of extra items are not shown and thus unable to print.
What can be the other way if i do not use JTable?
Or a solution with JTable itself.
What i want is to extend my whole dialog vertically if no. of items exceeded rather than using autoscrolls in JTable's scrollpane.
I hope i am clear to my question.
Here is the image of what i am trying.
I wouldn't use Swing components as printed components. Instead I'd build a PDF of the receipt and let the user print that. Scrolling is just going to be a problem with printing actual swing components that isn't easy to handle. This is a great PDF library:
http://pdfbox.apache.org/
This is weird - maybe it has a really simple solution, but I have spent two days on it so far! I have a JList in a scroll pane that I want to tab up and down in (and/or use up and down arrows).
I want to position the cursor at the first entry, and colour it, when the JList is displayed. The only way I've found to do this is to select the first entry, then request focus for the JList from inside the cell renderer - in the code that colours the selected row.
This works, but it changes the JTextField immediately below the scroll pane to non-editable. Remove the request focus from the cell renderer code, and the JTextField becomes editable again - but then I have to click on the JList to use the arrows on it or tab through it. Of course, I may be using totally the wrong tools. Help would be much appreciated...
I have just read that only one component can be focusable at a time - but why won't setFocusable() + requestFocusInWindow() change the focus to where I need it? I assume this is why the JTextField is not editable, even though it was set using setEditable(true)...? Are there other requirements that have to be in place before you can make a field focusable/editable?