我在JScrollPane上用draw画图,写字,超过了显示范围,滚动条怎么不出现 http://expert.csdn.net/Expert/topic/2303/2303573.xml?temp=.2948877 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要使用jscrollpane.getViewport().setPreferredSize(Dimension)方法 付代码package zsg.project.webprint;import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: ZSG_OnLine</p> * @author zsg * @version 1.0 */public class Applet1 extends JApplet { private boolean isStandalone = false; ppPanel panel = new ppPanel(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); this.getContentPane().add(panel, BorderLayout.CENTER); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } //static initializer for setting look & feel static { try { //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { } }}class ppPanel extends JScrollPane { FontMetrics titleFM; Font titleFont; //标题字体 Font normalFont; //正常字体 Font labelFont;//标注字体 public ppPanel() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.setLayout(null); titleFont = new Font("Simsun", 1, 16); normalFont = new Font("Serif", 0, 12); labelFont = new Font("Simsun", 1, 10); titleFM = this.getFontMetrics(titleFont); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; drawHead(g2,new String[3]); drawBotton(g2); } /** * 绘制头 * @param g2 */ public void drawHead(Graphics2D g2,String headName[]){ g2.draw3DRect(4,4,592,20,true); } /** * 绘制尾 * @param g2 */ public void drawBotton(Graphics2D g2){ g2.drawString("现在时间:2003-09-27",12,200); String write ="签名: "; g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450); }} class ppPanel extends JScrollPane ?这里不行啊改成:class ppPanel extends JPanel然后 改一下jbInit() private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); JScrollPane jScrollPane = new JScrollPane(new ppPanel()); jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000)) this.getContentPane().add(panel, BorderLayout.CENTER); } JScrollePanel不是为了直接在上面画图而产生的。楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。 按照几位的说法《JScrollePanel不是为了直接在上面画图而产生的。楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。》这么改过了,一样不管用。哪位实现了再告诉我 jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))应该可以了啊 jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))应该可以了啊 package zsg.project.webprint;import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: ZSG_OnLine</p> * @author zsg * @version 1.0 */public class Applet1 extends JApplet { private boolean isStandalone = false; ppPanel panel = new ppPanel(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); JScrollPane jScrollPane = new JScrollPane(new ppPanel()); jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000)); this.getContentPane().add(panel, BorderLayout.CENTER); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } //static initializer for setting look & feel static { try { //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { } }}class ppPanel extends JScrollPane { FontMetrics titleFM; Font titleFont; //标题字体 Font normalFont; //正常字体 Font labelFont;//标注字体 public ppPanel() { try { this.setSize(new Dimension(600,450)); jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.setLayout(null); titleFont = new Font("Simsun", 1, 16); normalFont = new Font("Serif", 0, 12); labelFont = new Font("Simsun", 1, 10); titleFM = this.getFontMetrics(titleFont); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; drawHead(g2,new String[3]); drawBotton(g2); } /** * 绘制头 * @param g2 */ public void drawHead(Graphics2D g2,String headName[]){ g2.draw3DRect(4,4,592,20,true); } /** * 绘制尾 * @param g2 */ public void drawBotton(Graphics2D g2){ g2.drawString("现在时间:2003-09-27",12,200); String write ="签名: "; g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450); }} 你的问题是JScrollPane 没有加进Applet private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); JScrollPane jScrollPane = new JScrollPane(new ppPanel()); jScrollPane.getViewport().add(panel); panel.setPreferredSize(new Dimension(1000,1000)); this.getContentPane().add(jScrollPane, BorderLayout.CENTER); } private void jbInit() throws Exception { this.setSize(new Dimension(400,300)); JScrollPane jScrollPane = new JScrollPane(panel); panel.setPreferredSize(new Dimension(1000,1000)); this.getContentPane().add(jScrollPane, BorderLayout.CENTER); } wolfsquare(狼平方 Swing报表工人) 的方法是对的.. 字符串连接"sdfs","sdfsdfsd"用什么好呢? Java Swing Jpanel 设置透明后的背景问题 Double类型的数据如何保留两位小数? 请高手进来帮忙!一个SQL语句异常 请教一个关于jTree展开的问题 关于swing滚动条的问题~~大家多帮帮忙哦!:) JAVA高手请帮帮我这个新手啊~ 请问怎莫在jbuilder9中布局???? 一个另我郁闷以久的问题,还请各位高手多多指教!先谢过各位了! win2k如何卸载ie,10分奉上!!!! 如何让窗口在屏幕居中显示?对窗口的管理 有没有人用过HSQL,或者读过它的代码,求救!
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: ZSG_OnLine</p>
* @author zsg
* @version 1.0
*/public class Applet1 extends JApplet {
private boolean isStandalone = false;
ppPanel panel = new ppPanel();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} //Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
this.getContentPane().add(panel, BorderLayout.CENTER);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
} //static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}class ppPanel extends JScrollPane {
FontMetrics titleFM;
Font titleFont; //标题字体
Font normalFont; //正常字体
Font labelFont;//标注字体 public ppPanel() {
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
} void jbInit() throws Exception {
this.setLayout(null);
titleFont = new Font("Simsun", 1, 16);
normalFont = new Font("Serif", 0, 12);
labelFont = new Font("Simsun", 1, 10);
titleFM = this.getFontMetrics(titleFont);
} public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawHead(g2,new String[3]);
drawBotton(g2);
} /**
* 绘制头
* @param g2
*/
public void drawHead(Graphics2D g2,String headName[]){
g2.draw3DRect(4,4,592,20,true);
} /**
* 绘制尾
* @param g2
*/
public void drawBotton(Graphics2D g2){
g2.drawString("现在时间:2003-09-27",12,200);
String write ="签名: ";
g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450);
}}
这里不行啊
改成:
class ppPanel extends JPanel然后 改一下jbInit()
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
JScrollPane jScrollPane = new JScrollPane(new ppPanel());
jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000))
this.getContentPane().add(panel, BorderLayout.CENTER);
}
楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。
楼主可以将一个JPanle加入JScrollePanel,在JPanel上画,然后设置它的大小就好了。》这么改过了,一样不管用。哪位实现了再告诉我
应该可以了啊
应该可以了啊
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: ZSG_OnLine</p>
* @author zsg
* @version 1.0
*/public class Applet1 extends JApplet {
private boolean isStandalone = false;
ppPanel panel = new ppPanel();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} //Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
JScrollPane jScrollPane = new JScrollPane(new ppPanel());
jScrollPane.getViewport().setPreferredSize(new Dimension(1000,1000));
this.getContentPane().add(panel, BorderLayout.CENTER);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
} //static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}class ppPanel extends JScrollPane {
FontMetrics titleFM;
Font titleFont; //标题字体
Font normalFont; //正常字体
Font labelFont;//标注字体 public ppPanel() {
try {
this.setSize(new Dimension(600,450));
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
} void jbInit() throws Exception {
this.setLayout(null);
titleFont = new Font("Simsun", 1, 16);
normalFont = new Font("Serif", 0, 12);
labelFont = new Font("Simsun", 1, 10);
titleFM = this.getFontMetrics(titleFont);
} public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawHead(g2,new String[3]);
drawBotton(g2);
} /**
* 绘制头
* @param g2
*/
public void drawHead(Graphics2D g2,String headName[]){
g2.draw3DRect(4,4,592,20,true);
} /**
* 绘制尾
* @param g2
*/
public void drawBotton(Graphics2D g2){
g2.drawString("现在时间:2003-09-27",12,200);
String write ="签名: ";
g2.drawString(write,(this.getBounds().width-titleFM.stringWidth(write)),450);
}}
this.setSize(new Dimension(400,300)); JScrollPane jScrollPane = new JScrollPane(new ppPanel());
jScrollPane.getViewport().add(panel);
panel.setPreferredSize(new Dimension(1000,1000));
this.getContentPane().add(jScrollPane, BorderLayout.CENTER);
}
this.setSize(new Dimension(400,300));
JScrollPane jScrollPane = new JScrollPane(panel);
panel.setPreferredSize(new Dimension(1000,1000));
this.getContentPane().add(jScrollPane, BorderLayout.CENTER);
}