java代码实现弹出新窗口,并把数据传给新窗口,类似预览的效果想要达到java代码预览你说java代码预览的效果java代码预览 , 用Struts不行的java代码预览,要不然不会出现俩页面的 。可以用js库的window.open来做,参数的传递可以用json 。这样会弹出一个自定义的新窗口,不用走什么请求 。
java中多张blob图片如何在前台预览,要求这些图片同时显示,最好有代码//您好 , 提问者:
比如您后台查询的是个List集合数组,前台接受 。
ListString list = new ArrayListString(); //import 你懂的
list.add("D:\\xx.jpg");//我不是查询数据库,手动添加图片地址,你也懂的
list.add("D:\\xx1.jpg");
//这个时候如果struts2的话list是public有set get的话肯定前台能拿到
//如果不是就放到request.setAttribute("list",list);中
这下面是页面代码:
%
List list = request.getAttribute("list");
for(int i = 0; ilist.size(); i){%
img src="https://www.04ip.com/post/%=list.get(i)%"/
%}%
java实现图片预览功能,可以显示缩列图,具有上下页的功能求技术支持把图片按照规定的比例压缩 , 然后保存至FTP,列表读取缩略图,单击显示原图 。
/**
* 压缩图片方法一(高质量)
* @param oldFile 将要压缩的图片
* @param width 压缩宽
* @param height 压缩高
* @param smallIcon 压缩图片后,添加的扩展名(在图片后缀名前添加)
* @param quality 压缩质量 范围:i0.0-1.0/i 高质量:i0.75/i 中等质量:i0.5/i 低质量:i0.25/i
* @param percentage 是否等比压缩 若true宽高比率将将自动调整
*/
public static void compressImage(String oldFile, int width, int height, String smallIcon,
float quality, boolean percentage) {
try {
File file = new File(oldFile);
// 验证文件是否存在
if(!file.exists())
throw new FileNotFoundException("找不到原图片!");
// 获取图片信息
BufferedImage image = ImageIO.read(file);
int orginalWidth = image.getWidth();
int orginalHeight = image.getHeight();
// 验证压缩图片信息
if (width = 0 || height = 0 || !Pattern.matches("^[1-9]\\d*$", String.valueOf(width))
|| !Pattern.matches("^[1-9]\\d*$", String.valueOf(height)))
throw new Exception("图片压缩后的高宽有误!");
// 等比压缩
if (percentage) {
double rate1 = ((double) orginalWidth) / (double) width0.1;
double rate2 = ((double) orginalHeight) / (double) height0.1;
double rate = rate1rate2 ? rate1 : rate2;
width = (int) (((double) orginalWidth) / rate);
height = (int) (((double) orginalHeight) / rate);
}
// 压缩后的文件名
String filePrex = oldFile.substring(0, oldFile.lastIndexOf('.'));
String newImage = filePrexsmallIconoldFile.substring(filePrex.length());
// 压缩文件存放位置
File savedFile = new File(newImage);
// 创建一个新的文件
savedFile.createNewFile();
// 创建原图像的缩放版本
Image image2 = image.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);
// 创建数据缓冲区图像
BufferedImage bufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 创建一个Graphics2D
Graphics2D g2 = bufImage.createGraphics();
// 重绘图像
g2.drawImage(image2, 0, 0, width, height, null);
g2.dispose();
// 过滤像素矩阵
float[] kernelData = https://www.04ip.com/post/{
-0.125f, -0.125f, -0.125f,
-0.125f, 2, -0.125f, -0.125f,
-0.125f, -0.125f };
Kernel kernel = new Kernel(3, 3, kernelData);
// 按核数学源图像边缘的像素复制为目标中相应的像素输出像素
ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
// 转换像素
bufImage = cOp.filter(bufImage, null);
FileOutputStream out = new FileOutputStream(savedFile);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufImage);
// 设置压缩质量
param.setQuality(quality, true);
encoder.encode(bufImage, param);
out.close();
System.out.println(newImage);
} catch (Exception e) {
e.printStackTrace();
System.out.println("压缩失败!"e.getMessage());
}
}
java swing jtable 打印 打印预览(求代码)JDK 1.4
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.*;
public class TextAreaRenderer extends JTextArea
implements TableCellRenderer {
private final DefaultTableCellRenderer adaptee =
new DefaultTableCellRenderer();
/** map from table to map of rows to map of column heights */
private final Map cellSizes = new HashMap();
public TextAreaRenderer() {
setLineWrap(true);
setWrapStyleWord(true);
}
public Component getTableCellRendererComponent(//
JTable table, Object obj, boolean isSelected,
boolean hasFocus, int row, int column) {
// set the colours, etc. using the standard for that platform
adaptee.getTableCellRendererComponent(table, obj,
isSelected, hasFocus, row, column);
setForeground(adaptee.getForeground());
setBackground(adaptee.getBackground());
setBorder(adaptee.getBorder());
setFont(adaptee.getFont());
setText(adaptee.getText());
// This line was very important to get it working with JDK1.4
TableColumnModel columnModel = table.getColumnModel();
setSize(columnModel.getColumn(column).getWidth(), 100000);
int height_wanted = (int) getPreferredSize().getHeight();
addSize(table, row, column, height_wanted);
height_wanted = findTotalMaximumRowSize(table, row);
if (height_wanted != table.getRowHeight(row)) {
table.setRowHeight(row, height_wanted);
}
return this;
}
private void addSize(JTable table, int row, int column,
int height) {
Map rows = (Map) cellSizes.get(table);
if (rows == null) {
cellSizes.put(table, rows = new HashMap());
}
Map rowheights = (Map) rows.get(new Integer(row));
if (rowheights == null) {
rows.put(new Integer(row), rowheights = new HashMap());
}
rowheights.put(new Integer(column), new Integer(height));
}
/**
* Look through all columns and get the renderer.If it is
* also a TextAreaRenderer, we look at the maximum height in
* its hash table for this row.
*/
private int findTotalMaximumRowSize(JTable table, int row) {
int maximum_height = 0;
Enumeration columns = table.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn tc = (TableColumn) columns.nextElement();
TableCellRenderer cellRenderer = tc.getCellRenderer();
if (cellRenderer instanceof TextAreaRenderer) {
TextAreaRenderer tar = (TextAreaRenderer) cellRenderer;
maximum_height = Math.max(maximum_height,
tar.findMaximumRowSize(table, row));
}
}
return maximum_height;
}
private int findMaximumRowSize(JTable table, int row) {
Map rows = (Map) cellSizes.get(table);
if (rows == null) return 0;
Map rowheights = (Map) rows.get(new Integer(row));
if (rowheights == null) return 0;
int maximum_height = 0;
for (Iterator it = rowheights.entrySet().iterator();
it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
int cellHeight = ((Integer) entry.getValue()).intValue();
maximum_height = Math.max(maximum_height, cellHeight);
}
return maximum_height;
}
}
import javax.swing.*;
public class TextAreaEditor extends DefaultCellEditor {
public TextAreaEditor() {
super(new JTextField());
final JTextArea textArea = new JTextArea();
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBorder(null);
editorComponent = scrollPane;
delegate = new DefaultCellEditor.EditorDelegate() {
public void setValue(Object value) {
textArea.setText((value != null) ? value.toString() : "");
}
public Object getCellEditorValue() {
return textArea.getText();
}
};
}
}
import javax.swing.*;
import javax.swing.table.*;
public class TextAreaRendererTest extends JFrame {
private final JTable table = new JTable(10, 4);
public TextAreaRendererTest() {
super(System.getProperty("java.vm.version"));
// We use our cell renderer for columns 1, 2, 3
TableColumnModel cmodel = table.getColumnModel();
TextAreaRenderer textAreaRenderer = new TextAreaRenderer();
cmodel.getColumn(1).setCellRenderer(textAreaRenderer);
cmodel.getColumn(2).setCellRenderer(new TextAreaRenderer());
// I am demonstrating that you can have several renderers in
// one table, and they communicate with one another in
// deciding the row height.
cmodel.getColumn(3).setCellRenderer(textAreaRenderer);
TextAreaEditor textEditor = new TextAreaEditor();
cmodel.getColumn(1).setCellEditor(textEditor);
cmodel.getColumn(2).setCellEditor(textEditor);
cmodel.getColumn(3).setCellEditor(textEditor);
String test = "The lazy dog jumps over the quick brown fox";
for (int column = 0; column4; column) {
table.setValueAt(test, 0, column);
table.setValueAt(test, 4, column);
}
test = testtesttesttesttesttesttesttest;
table.setValueAt(test, 4, 2);
getContentPane().add(new JScrollPane(table));
setSize(600, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new TextAreaRendererTest();
}
}
我的例子 自己看看
如何用java实现图片预览功能 , 求代码使用两种不同java代码预览的方法实现图片预览功能
Java代码
BODY
script language="javascript"
function ShowImage(path){
document.all.divShow.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = https://www.04ip.com/post/path;
}
function test(){
document.all.showimg.src=https://www.04ip.com/post/document.all.file1.value;
}
/script
INPUT style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 272px" type="file"onchange="ShowImage(this.value)"
div id="divShow" style="FILTER:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);WIDTH:274px;HEIGHT:100px"
input type="file" id="file1" onchange="test()"br/
img id="showimg" style="width:200px;height:200px;"
/BODY
【java代码预览 java实现在线预览】关于java代码预览和java实现在线预览的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- wii双人射击游戏,wii 双人
- java代码写正则报错,java正则\s
- erp系统实施前的准备,erp实施前的准备工作
- 游戏代理的软件,最有良心的游戏代理
- 手机怎么远程mysql 手机怎么远程一起看视频
- fluttermvvm模式,flutterdemo
- 2014813是什么cpu,1474是什么处理器
- 找地推公众号怎么找到,怎么找到地推公司
- oracle包如何写 oracle包的使用