- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 Java,我正在使用 GridBagLayout 创建一个表单。 GUI 位于 JPanel 内,JPanel 位于添加到 JFrame 的scrollPane 内。
我希望带有 GUI 的 JPanel 具有固定大小,以防止表单被拉伸(stretch),但是,我希望 JScrollPanel 能够根据用户的偏好调整大小。 (类似于 MS Paint, Canvas 是我的 JPanel)。我想防止表单被拉伸(stretch)的原因是因为我希望它能够打印,从我现在的方式来看,打印的表单几乎按照我想要的方式打印,但如果框架在之前调整了大小,则会发生不利的改变打印。
也许我的问题最好通过打印的方式来解决,但问题是我以前从未处理过这种级别的打印,无法找到类似的问题/教程来帮助我解决问题。我的方向可能是“穷人的方式”,但它是目前唯一对我有意义的方式,我是一名相当新手的 Java 程序员。
FrontierMain.java
public class FrontierMain {
public FrontierMain(){
JFrame frame = new JFrame();
frame.setTitle("Frontier Insulation Labor Record Tool");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
LaborRecordPanel recordPanel = new LaborRecordPanel();
frame.add(recordPanel.scrollPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
FrontierMain fm = new FrontierMain();
}
});
System.out.println("Hello, World");
}
}
LaborRecordPanel.java
public class LaborRecordPanel implements
Printable, ActionListener {
private Color shade = new Color(201,201,201); // color for shaded cells
private JLabel dateSpace[] = new JLabel[7];
private JLabel grandTotalSpace = new JLabel();
private JLabel locAndDescSpace = new JLabel();
private JLabel personnelSpace[] = new JLabel[10]; // empty cells
private JLabel calendarGridLines[] = new JLabel[300]; //empty labels for gridlines
private ImageIcon logoIcon = new ImageIcon("Images/fici_logo1.jpg");
private JLabel logoLabel = new JLabel(logoIcon);
private JLabel authorizedBy = new JLabel("AUTHORIZED BY:");
private JLabel toCertify = new JLabel("THIS IS TO CERTIFY THAT THE ABOVE LABOR HAS BEEN PERFORMED.");
private JLabel laborRecordNO = new JLabel("NO.");
private JLabel nameOfJob = new JLabel("NAME OF JOB:");
private JLabel customerPO = new JLabel("CUSTOMER PO #:");
private JLabel contractNO = new JLabel("CONTRACT NO.");
private JLabel weekEnding = new JLabel("WEEK ENDING");
private JLabel personnelList = new JLabel("<html>LIST SUPERVISION &<br> CRAFT LABOR BELOW:</html>");
private JLabel locAndDescriptionLabel = new JLabel("LOCATION AND DESCRIPTION:");
private JLabel personnelTitle = new JLabel("TITLE");
private JLabel supt = new JLabel("SUPT.");
private JLabel foreman = new JLabel("FOREMAN");
private JLabel[] mechanic= new JLabel[8];
private JLabel calendarTitle = new JLabel("NUMBER OF HOURS WORKED @ SITE");
private JLabel dayHeading = new JLabel("DAY");
private JLabel dateHeading = new JLabel("DATE");
private JLabel[] ot2 = new JLabel[10];
private JLabel[] ot1 = new JLabel[10];
private JLabel[] st = new JLabel[10];
private JLabel mon = new JLabel("MON");
private JLabel tues = new JLabel("TUES");
private JLabel wed = new JLabel("WED");
private JLabel thur = new JLabel("THUR");
private JLabel fri = new JLabel("FRI");
private JLabel sat = new JLabel("SAT");
private JLabel sun = new JLabel("SUN");
private JLabel totalHours = new JLabel("<html>TOTAL<br> HOURS</html>");
private JLabel ratePerHour = new JLabel("<html>RATE<br> PER<br> HOUR</html>");
private JLabel totalAmount = new JLabel("<html>TOTAL<br> AMOUNT</html>");
private JLabel grandTotal = new JLabel("TOTAL");
JPanel rp = new JPanel();
JScrollPane scrollPane = new JScrollPane(rp);
LaborRecordPanel(){
rp.setPreferredSize(new Dimension(1295,1830 ));
rp.setMinimumSize(new Dimension(1295,1830 ));
rp.setMaximumSize(new Dimension(1295,1830 ));
scrollPane.setPreferredSize(new Dimension(900,700 ));
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //increase the scroll speed
for (int i = 0; i <= 7; i++) mechanic[i] = new JLabel("MECHANIC"); // create mechanic labels
for (int i = 0; i <= 9; i++) //create labels for work time
{
ot2[i] = new JLabel("OT-2");
ot1[i] = new JLabel("OT-1");
st[i] = new JLabel("S.T.");
}
//create empty labels for gridlines
for (int i = 0; i <= 9; i++) personnelSpace[i] = new JLabel();
for (int i = 0; i <= 6; i++) dateSpace[i] = new JLabel();
for (int i = 0; i <= 299; i++) calendarGridLines[i] = new JLabel();
GridBagLayout gridbag = new GridBagLayout();
rp.setBackground(Color.WHITE);
rp.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
GridBagConstraints gbc = new GridBagConstraints();
rp.setLayout(gridbag);
//gbc.insets = new Insets(5, 5, 5, 5);
//row 0////////////////////////////////////////////////////////////
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 10;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.gridheight = 1;
gbc.gridwidth = 1;
laborRecordNO.setHorizontalAlignment(JLabel.CENTER);
laborRecordNO.setFont(new Font("Dialog", Font.PLAIN, 18));
gridbag.setConstraints(laborRecordNO, gbc);
rp.add(laborRecordNO, gbc);
//row 1////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 13;
gridbag.setConstraints(logoLabel, gbc);
rp.add(logoLabel, gbc);
//row 2////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth = 1;
nameOfJob.setFont(nameOfJob.getFont().deriveFont(18.0f));
gridbag.setConstraints(nameOfJob, gbc);
rp.add(nameOfJob, gbc);
gbc.gridx = 6;
gbc.gridy = 2;
gbc.gridheight = 1;
gbc.gridwidth = 3;
contractNO.setFont(contractNO.getFont().deriveFont(18.0f));
gridbag.setConstraints(contractNO, gbc);
rp.add(contractNO, gbc);
//row 3////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridheight = 1;
gbc.gridwidth = 1;
customerPO.setFont(customerPO.getFont().deriveFont(18.0f));
gridbag.setConstraints(customerPO, gbc);
rp.add(customerPO, gbc);
gbc.gridx = 6;
gbc.gridy = 3;
gbc.gridheight = 1;
gbc.gridwidth = 3;
weekEnding.setFont(weekEnding.getFont().deriveFont(18.0f));
gridbag.setConstraints(weekEnding, gbc);
rp.add(weekEnding, gbc);
//row 4////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 4;
gbc.gridheight = 3;
gbc.gridwidth = 1;
personnelList.setHorizontalAlignment(JLabel.CENTER);
personnelList.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
personnelList.setFont(personnelList.getFont().deriveFont(18.0f));
gridbag.setConstraints(personnelList, gbc);
rp.add(personnelList, gbc);
gbc.gridx = 1;
gbc.gridy = 4;
gbc.gridheight = 3;
gbc.gridwidth = 1;
personnelTitle.setHorizontalAlignment(JLabel.CENTER);
personnelTitle.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.BLACK));
personnelTitle.setFont(personnelTitle.getFont().deriveFont(18.0f));
gridbag.setConstraints(personnelTitle, gbc);
rp.add(personnelTitle, gbc);
gbc.gridx = 2;
gbc.gridy = 4;
gbc.gridwidth = 8;
gbc.gridheight = 1;
calendarTitle.setHorizontalAlignment(JLabel.CENTER);
calendarTitle.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.BLACK));
calendarTitle.setFont(calendarTitle.getFont().deriveFont(18.0f));
gridbag.setConstraints(calendarTitle, gbc);
rp.add(calendarTitle, gbc);
gbc.gridx = 10;
gbc.gridy = 4;
gbc.gridheight = 3;
gbc.gridwidth = 1;
totalHours.setHorizontalAlignment(JLabel.CENTER);
totalHours.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK));
totalHours.setFont(totalHours.getFont().deriveFont(18.0f));
gridbag.setConstraints(totalHours, gbc);
rp.add(totalHours, gbc);
gbc.gridx = 11;
gbc.gridy = 4;
gbc.gridheight = 3;
gbc.gridwidth = 1;
ratePerHour.setHorizontalAlignment(JLabel.CENTER);
ratePerHour.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.BLACK));
ratePerHour.setFont(ratePerHour.getFont().deriveFont(18.0f));
gridbag.setConstraints(ratePerHour, gbc);
rp.add(ratePerHour, gbc);
gbc.gridx = 12;
gbc.gridy = 4;
gbc.gridheight = 3;
gbc.gridwidth = 1;
totalAmount.setHorizontalAlignment(JLabel.CENTER);
totalAmount.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK));
totalAmount.setFont(totalAmount.getFont().deriveFont(18.0f));
gridbag.setConstraints(totalAmount, gbc);
rp.add(totalAmount, gbc);
//row 5//////////////////////////////////////////////////////////////////
gbc.gridx = 2;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
dayHeading.setHorizontalAlignment(JLabel.CENTER);
dayHeading.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
dayHeading.setFont(dayHeading.getFont().deriveFont(18.0f));
gridbag.setConstraints(dayHeading, gbc);
rp.add(dayHeading, gbc);
gbc.gridx = 3;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
mon.setHorizontalAlignment(JLabel.CENTER);
mon.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
mon.setFont(mon.getFont().deriveFont(18.0f));
gridbag.setConstraints(mon, gbc);
rp.add(mon, gbc);
gbc.gridx = 4;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
tues.setHorizontalAlignment(JLabel.CENTER);
tues.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
tues.setFont(tues.getFont().deriveFont(18.0f));
gridbag.setConstraints(tues, gbc);
rp.add(tues, gbc);
gbc.gridx = 5;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
wed.setHorizontalAlignment(JLabel.CENTER);
wed.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
wed.setFont(wed.getFont().deriveFont(18.0f));
gridbag.setConstraints(wed, gbc);
rp.add(wed, gbc);
gbc.gridx = 6;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
thur.setHorizontalAlignment(JLabel.CENTER);
thur.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
thur.setFont(thur.getFont().deriveFont(18.0f));
gridbag.setConstraints(thur, gbc);
rp.add(thur, gbc);
gbc.gridx = 7;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
fri.setHorizontalAlignment(JLabel.CENTER);
fri.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
fri.setFont(fri.getFont().deriveFont(18.0f));
gridbag.setConstraints(fri, gbc);
rp.add(fri, gbc);
gbc.gridx = 8;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
sat.setHorizontalAlignment(JLabel.CENTER);
sat.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
sat.setFont(sat.getFont().deriveFont(18.0f));
gridbag.setConstraints(sat, gbc);
rp.add(sat, gbc);
gbc.gridx = 9;
gbc.gridy = 5;
gbc.gridheight = 1;
gbc.gridwidth = 1;
sun.setHorizontalAlignment(JLabel.CENTER);
sun.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
sun.setFont(sun.getFont().deriveFont(18.0f));
gridbag.setConstraints(sun, gbc);
rp.add(sun, gbc);
//row 6//////////////////////////////////////////////////////////////
gbc.gridx = 2;
gbc.gridy = 6;
gbc.gridheight = 1;
gbc.gridwidth = 1;
dateHeading.setHorizontalAlignment(JLabel.CENTER);
dateHeading.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
dateHeading.setFont(dateHeading.getFont().deriveFont(18.0f));
gridbag.setConstraints(dateHeading, gbc);
rp.add(dateHeading, gbc);
int dateSpaceIndex = 3;
boolean flip = true;
for (int k = 0; k <= 6; k++)//create gridlines for day area
{
gbc.gridx = dateSpaceIndex;
gbc.gridy = 6;
gbc.gridheight = 1;
gbc.gridwidth = 1;
if(flip) dateSpace[k].setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
else dateSpace[k].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
gridbag.setConstraints(dateSpace[k], gbc);
rp.add(dateSpace[k], gbc);
dateSpaceIndex++;
flip = !flip;
}
//row 7/////////////////////////////////////////////////////////////
gbc.gridx = 1;
gbc.gridy = 7;
gbc.gridheight = 3;
gbc.gridwidth = 1;
supt.setHorizontalAlignment(JLabel.CENTER);
supt.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
supt.setFont(supt.getFont().deriveFont(18.0f));
gridbag.setConstraints(supt, gbc);
rp.add(supt, gbc);
//row 10///////////////////////////////////////////////////////////
gbc.gridx = 1;
gbc.gridy = 10;
gbc.gridheight = 3;
gbc.gridwidth = 1;
foreman.setHorizontalAlignment(JLabel.CENTER);
foreman.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
foreman.setFont(foreman.getFont().deriveFont(18.0f));
gridbag.setConstraints(foreman, gbc);
rp.add(foreman, gbc);
//row 13-36 plus 7-12 time worked labels//////////////////////////
for (int r = 0; r <= 7; r++)
{
gbc.gridx = 1;
gbc.gridy = 13 + (3*r);
gbc.gridheight = 3;
gbc.gridwidth = 1;
mechanic[r].setHorizontalAlignment(JLabel.CENTER);
mechanic[r].setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
mechanic[r].setFont(mechanic[r].getFont().deriveFont(18.0f));
gridbag.setConstraints(mechanic[r], gbc);
rp.add(mechanic[r], gbc);
}
for (int c = 0; c <= 9; c++){
gbc.gridx = 2;
gbc.gridy = 7 + (3*c);
gbc.gridheight = 1;
gbc.gridwidth = 1;
ot2[c].setHorizontalAlignment(JLabel.CENTER);
ot2[c].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
ot2[c].setFont(ot2[c].getFont().deriveFont(18.0f));
gridbag.setConstraints(ot2[c], gbc);
rp.add(ot2[c], gbc);
gbc.gridx = 2;
gbc.gridy = 8 + (3*c);
gbc.gridheight = 1;
gbc.gridwidth = 1;
ot1[c].setHorizontalAlignment(JLabel.CENTER);
ot1[c].setOpaque(true);
ot1[c].setBackground(shade);
ot1[c].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
ot1[c].setFont(ot1[c].getFont().deriveFont(18.0f));
gridbag.setConstraints(ot1[c], gbc);
rp.add(ot1[c], gbc);
gbc.gridx = 2;
gbc.gridy = 9 + (3*c);
gbc.gridheight = 1;
gbc.gridwidth = 1;
st[c].setHorizontalAlignment(JLabel.CENTER);
st[c].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
st[c].setFont(st[c].getFont().deriveFont(18.0f));
gridbag.setConstraints(st[c], gbc);
rp.add(st[c], gbc);
}
//row 37/////////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 37;
gbc.gridheight = 1;
gbc.gridwidth = 1;
locAndDescriptionLabel.setFont(locAndDescriptionLabel.getFont().deriveFont(18.0f));
gridbag.setConstraints(locAndDescriptionLabel, gbc);
rp.add(locAndDescriptionLabel);
gbc.gridx = 11;
gbc.gridy = 37;
gbc.gridheight = 1;
gbc.gridwidth = 1;
grandTotal.setHorizontalAlignment(JLabel.CENTER);
grandTotal.setOpaque(true);
grandTotal.setBackground(Color.BLACK);
grandTotal.setForeground(Color.WHITE);
grandTotal.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
grandTotal.setFont(grandTotal.getFont().deriveFont(18.0f));
gridbag.setConstraints(grandTotal, gbc);
rp.add(grandTotal);
gbc.gridx = 12;
gbc.gridy = 37;
gbc.gridwidth = 1;
gbc.gridheight = 1;
grandTotalSpace.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
gridbag.setConstraints(grandTotalSpace, gbc);
rp.add(grandTotalSpace);
//row 38////////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 38;
gbc.gridwidth = 10;
gbc.gridheight = 1;
gbc.ipady = 80;
locAndDescSpace.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
gridbag.setConstraints(locAndDescSpace, gbc);
rp.add(locAndDescSpace);
//row 39////////////////////////////////////////////////////////////////
gbc.ipady = 0; //reset to default
gbc.gridx = 0;
gbc.gridy = 39;
gbc.gridheight = 1;
gbc.gridwidth = 2;
toCertify.setFont(toCertify.getFont().deriveFont(18.0f));
gridbag.setConstraints(toCertify, gbc);
rp.add(toCertify);
//row 40///////////////////////////////////////////////////////////////
gbc.gridx = 0;
gbc.gridy = 40;
gbc.gridheight = 1;
gbc.gridwidth = 3;
authorizedBy.setFont(authorizedBy.getFont().deriveFont(18.0f));
gridbag.setConstraints(authorizedBy, gbc);
rp.add(authorizedBy);
for (int r = 0; r <= 9; r++)//gridlines for personnel space
{
gbc.gridx = 0;
gbc.gridy = 7 + (3*r);
gbc.gridheight = 3;
gbc.gridwidth = 1;
personnelSpace[r].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
gridbag.setConstraints(personnelSpace[r], gbc);
rp.add(personnelSpace[r]);
}
//create calendar grid lines
int yPointer = 7;
int xPointer = 3;
int shadePtr = 8;
for (int j = 0; j <= 299; j++)
{
gbc.gridx = xPointer;
gbc.gridy = yPointer;
gbc.gridheight = 1;
gbc.gridwidth = 1;
calendarGridLines[j].setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
if (yPointer == shadePtr){ //if row number = shadePtr then color the cell
calendarGridLines[j].setOpaque(true);
calendarGridLines[j].setBackground(shade);
}
gridbag.setConstraints(calendarGridLines[j], gbc);
rp.add(calendarGridLines[j]);
xPointer++; //go to next cell in row
j++; //use the next jlabel
gbc.gridx = xPointer;
gbc.gridy = yPointer;
gbc.gridheight = 1;
gbc.gridwidth = 1;
calendarGridLines[j].setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, Color.BLACK));
if (yPointer == shadePtr){ //if row number = shadePtr then color the cell
calendarGridLines[j].setOpaque(true);
calendarGridLines[j].setBackground(shade);
}
gridbag.setConstraints(calendarGridLines[j], gbc);
rp.add(calendarGridLines[j]);
xPointer++; //go to next cell in row
if(xPointer == 13) //if end of column then go to next row and reset column pointer to 3 and increment shade pointer by 3
{
yPointer++; //go down a row
xPointer = 3;
if((j % 3) == 0) {
shadePtr = yPointer;
}
}
}
JButton printTest = new JButton("PrintTest");
printTest.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 41;
gbc.gridheight = 1;
gbc.gridwidth = 1;
gridbag.setConstraints(printTest, gbc);
rp.add(printTest);
}
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog()){
try{
printJob.print();
}
catch(Exception ex){
throw new RuntimeException(ex);
}
}
}
@Override
public int print(Graphics g, PageFormat pf, int index)
throws PrinterException {
Graphics2D g2 = (Graphics2D)g;
if (index >= 1){
return Printable.NO_SUCH_PAGE;
}
else {
AffineTransform originalTransform = g2.getTransform();
double scaleX = pf.getImageableWidth() / rp.getWidth();
double scaleY = pf.getImageableHeight() / rp.getHeight();
// Maintain aspect ratio
double scale = Math.min(scaleX, scaleY);
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.scale(scale, scale);
rp.printAll(g2);
g2.setTransform(originalTransform);
return Printable.PAGE_EXISTS;
}
}
}
最佳答案
我将主 GUI 面板放在另一个 JPanel 中,该 JPanel 位于 JScrollPane 中。这会阻止我的主 GUI 调整到框架大小;相反,“外部”JPanel 会调整大小。
关于java - 如何防止 JPanel 调整大小以填充 JScrollPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21784537/
我有一个 JScrollPane,它的内容 Pane 有一个 JPanel。我向该 JPanel 添加了较小的 JPanel,正如预期的那样,如果我添加太多 JPanel,将会出现一个垂直滚动条。 问
我正在尝试在另一个 JScrollPane 中添加一个 JScrollPane。内部 JScrollPane 只会水平滚动,外部只会垂直滚动。 在这张图中,您可以看到添加 mainPanel 时水平滚
我正在尝试创建一个带有滚动条的容器,并且容器内部有两个内部面板。顶部内面板内还有另一个 JScrollPane。 但目前我遇到的问题是,当我的顶部内面板太长(宽度)时,顶部内面板内的滚动条被禁用,我只
你们能让我知道禁用水平滚动条的最佳方法是什么吗? 我有 宽度:100% 和 高度:280px 的 div。当我们有很长的连续文本(没有任何空格)时,我们会显示一个水平滚动条。 顺便说一句,我正在使用
我注意到这个问题主要出现在 OS 10.5.8 上的 Firefox 3.6.6 上,Safari 上偶尔也会出现这种情况(准备好惊讶的表情 - IE 实际上每次都工作正常 - 什么?!)。 我的网址
所以我有一堆JTable。每个JTable 都位于JScrollPane 内。然后,我将每个 JScrollPane 添加到 JPanel 中。然后,我将此 JPanel 添加到 JScrollPan
我在 JScrollPane 上放置了多个 JPanel。现在我有了它,所以如果你的鼠标在框架之外,那么它就不会拖动 JPanels。 当我在一个方向上移动组件时,我需要让它滚动。 (例如,如果我
有什么区别 JScrollPane.getViewportBorderBounds() and JScrollPane.getViewport() and JscrollPane.getVisible
此应用程序适用于触摸屏。我只需要仅当用户触摸 JScrollPane 区域时 JScrollPane 的滚动条可见。 我是 GUI 和 swing 的新手。这会很有帮助,我不明白是什么,或者如果在其他
出于布局目的,我需要在滚动内容底部和容器底部之间放置 15px 的空间:div class="scroll-pane" . 造型容器 .scroll-pane { padding-bottom:15p
我需要一个可以显示很多图像的程序,并且我需要一个可以滚动的窗口。我阅读了文档并在论坛上进行了搜索,但仍然没有成功。我尝试使用 JScrollPane 和 JFrame,如下所示。 JScrollPan
我今天遇到了这个新事物,但我不知道为什么。例如,当我想在面板中显示某些内容时,我只需将其添加到面板即可;但为什么我不能直接添加表格到滚动 Pane ,为什么我必须调用 setviewportview(
我今天遇到了这个新事物,我不知道为什么。例如,当我想在面板中显示某些内容时,我只需将其添加到面板即可;但是为什么我不能直接添加表格到滚动 Pane ,为什么我必须调用 setviewportview(
我一直在尝试缩小 JScrollPane 的内容宽度,例如。我已将 HorizontalScrollBarPolicy 设置为 NEVER,但这最终导致没有 ScrollBar 出现并且内容不再显
所以,在下面的代码中,我在左侧有一个 JTextArea。右上角的 JScrollPane 看起来不错。使用相同的代码,我还在右下侧添加了一个 JScrollPane,但是尽管代码相同,但保存了首选大
我在 div 上使用 JScrollPane 来滚动它。 div 包含一个自写的 javascript 代码,它从我的 tumblr 提要中获取最后几篇文章。但是,即使滚动 Pane 显示正常,但由于
请看下面的代码块 import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import javax.s
我在 Swing 中制作了一个简单的 GUI,其中在 JScrollPane 内、JSPlitPane 内、JPanel 内、....在 JFrame 内有一个大 JPanel(显示大 Buffere
我有一个带滚动条的 JPanel,我想向它添加很多 JLabel。但是滚动条不起作用。我无法使用滚动条,即使面板已满,它也不会滚动。这是我的代码: import java.awt.*; import
我正在尝试在 JScrollPane 中添加 2 个图像。第一个图像是背景,第二个图像与第一个图像重叠。当我运行我的程序时,问题只显示第二张图像! 请帮忙 ImageIcon ii = new Ima
我是一名优秀的程序员,十分优秀!