I have the following JTable in my program which is placed inside a JScrollPane. I made it using the GUI builder provided by Netbeans.
The problem is some of the columns in the table is not visible and there is no horizontal scroll bar. I even set the horizontalScrollBarPolicy to ALWAYS and it didnt help. So how do I make the table scrollable?
As #Andrew Thompson mentiond you should provide some code that addresses the problem. Without seeing your code it's hard to find out what's the problem. But a common workaround about that is as the following:
If you have correctly added your JTable to the ViewPort of a JScrollPane like this:
JTable jtable = new JTable();
//...
JScrollPane sc = new JScrollPane(jtable);
//sc.setViewportView(jtable); <- This way is correct too
//
getContentPane().add(sc);
Then the most probable problem is about the AutoResizeMode of your JTable. Try this:
jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Hope this would help you.
Related
So, I'm wondering how I would go about colouring certain words in my scrollpane. After doing some research I have found almost nothing helpful. What is there to help with colouring certain words?
JScrollPane scrollPane = new JScrollPane();
contentPane.add(scrollPane, BorderLayout.CENTER);
txtInfo = new JTextArea("Bot In Progress...\n");
txtInfo.setColumns(35);
txtInfo.setEnabled(false);
txtInfo.setDisabledTextColor(Color.black);
scrollPane.setViewportView(txtInfo);
So, here is my scrollpane. What I have it doing now is accepting outputs from part of my program and displaying them. Certain words that I want coloured are Win!(Green) and Loose(Red), and maybe some more later.
The reason why a scrollpane works the best for me is because I need the log to update constantly and the user is supposed to be able to look back up at the log at any time. Is there a better way of storing that information or what?
I don't think you can do it with JTextArea instead you can do it using JTextPane. You can then add the JTextPane to your JScrollPane. Have a look at this site http://javatechniques.com/blog/setting-jtextpane-font-and-color/ where it explains how to do this.
I am trying to make a small program..When I execute it, I insert rows and columns and then when I click a button a matrix is appeared on the screen. My problem is that when the number of rows is bigger , I cant see all the matrix and other things that are below, and I can not move down in the JFrame. How can I do this? how can I add a lift, or elevator, to make possible to move up and down? I am not sure if it is called a lift ( the object at the right of the window that helps us to move up and down). Please help me...Thank you in advance.
"how can I add a lift, or elevator, to make possible to move up and down? I am not sure if it is called a lift ( the object at the right of the window that helps us to move up and down)."
Wrap the JTable in a JScrollPane
JTable table = new JTable();
JScrollPane scroll = new JScrollPane(table);
container.add(scroll);
Make sure you remove the table from the container, as a component can only have one parent container
See How to Use ScrollPanes
add(new JScrollPane(tableName));
you should put it in your constructor.
it worked for me, good luck :)
I have a problem with JScrollPane - it looks like it lays over my JTable.
I have made a JTable without JScrollPane and everything seems to be fine - everything gets loaded as I wish and so on - but when I try to add JScrollPane everything goes wrong - only the column names are showing.
This is my code...
projectTable = new javax.swing.JTable();
ProjectTableModel ptm = new ProjectTableModel();
projectTable.setModel(ptm);
jScrollPane1.setViewportView(projectTable);
Is it a problem with positioning components? Could someone please help me with this problem.
The Oracle JTable tutorial contains a section about 'Adding a table to a container', where the container in the example is a JScrollPane
I'm trying to set the number of options shown in the JComboBox drop down list when it is used as a JTable RowFilter. Specifically, the filter on occasion can have many options and I'd like to show twice as many as the default (which appears to be 8). See this image:
Combox Box Example http://aalto.tv/test/combobox-image.png
As you can hopefully see, this ComboBox only shows 8 items and I would like to show more if there are more to be seen.
Having searched around the popular solution is to call "setMaximumRowCount" on the JComboBox, however this is having no effect.
Can any one point me in the right direction?
Many thanks for any and all help!
Cheers,
Alex
try the revalidate() (or repaint()) method after setting the rowcount;
if a setXX method does not generate an event to the component, then you have to manually reset it.
failing that, look at the source code of the setMaximumRowCount() method
JComboBox#setMaximumRowCount works for JTable / TableHeader and AutoComplete JComboBox in the JTable too
I have a problem in my table model to update the data I print in it.
I have the class AgendaTableModel who is the table model, and the class Screen that is the main UI, when I press the button 'Listar Contatos' the table model should appear on JScrollPane in the center of the JFrame, but it continues blank.
What should be the problem ?
You should really post the code or better an SSCCE.
Here's the Oracle's tutorial on JTable.
I'll give you some hints:
Each JTable has a TableModel associated
You don't display the TableModel but the JTable, that is a view of your model
When you add components dynamically you should revalidate the parent component, so if you are adding a JTable somewhere, try to revalidate its container.
If you are trying to add the JTable to an already existing JScrollPane (empty or containing something else), consider to instantiate a new JScrollPane rather than updating its content.