尝试在JScrollPane中包含JTable。但问题是,每次我向表中添加另一行时,JFrame的大小都会逐渐增加(下面的屏幕截图供参考)。我不希望它这样做。显然,由于它在滚动窗格中,如果我不断向表中添加行,我希望实际显示滚动条并用于向下滚动以查看表中的较低值。
屏幕截图:http://i.imgur.com/dUqQW7N.jpg
代码:
String[] columns = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
Object[][] data = {
{"Kathy", "Smith", "Snowboarding", 5, false},
{"John", "Doe", "Rowing", 3, true},
{"Sue", "Black", "Knitting", 2, false},
{"Jane", "White", "Speed reading", 20, true},
{"Joe", "Brown", "Pool", 10, false}
};
searchBox = new JTextField();
searchButton = new JButton();
rentCarButton = new JButton();
rentedCarsButton = new JButton();
table = new JTable(data, columns);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
scrollPane = new JScrollPane(table);
非常感谢任何帮助。
答案 0 :(得分:0)
Welp答案就在我面前,我刚刚更改了代码行
##include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#define MAX1 1024
#define Pxsize MAX1
#define Pysize Pxsize
//Kernel size
#define Kxsize 3
#define Kysize Kxsize
using namespace std;
using namespace cv;
unsigned short int A[Pxsize][Pysize];
unsigned short int B[Pxsize][Pysize];
unsigned short int K[Kxsize][Kysize];
int main(){
SINGLECORE // I use it to assign the program to a particular core of the CPU
//filter arguments
Point anchor;
double delta;
int ddepth;
//assign data between 0 and 255 to the input matrix
int i,j;
for (i=0; i<Pxsize; i++)
for (j=0; j<Pysize; j++)
A[i][j] = (i+j)%255;
//assign data to the kernel
//assign data between 0 and 255 to the input matrix
for (i=0; i<Kxsize; i++)
for (j=0; j<Kysize; j++)
K[i][j]=1;
cv::Mat input = cv::Mat(Pxsize, Pysize, CV_8UC1, A);
cv::Mat output = cv::Mat(Pxsize, Pysize, CV_8UC1, B);
cv::Mat kernel = cv::Mat::ones(Kxsize, Kysize, CV_8UC1);
// Initialize arguments for the filter
anchor = Point( -1, -1 );
delta = 0;
ddepth = -1;
filter2D( input, output, ddepth , kernel, anchor, delta, 1 );
return 0;
}
到
table.setPreferredScrollableViewportSize(table.getPreferredSize());
我感到愚蠢。