導航:首頁 > 編程語言 > java垂直居中

java垂直居中

發布時間:2022-09-14 23:44:37

⑴ 請問在java JTable中如何設置單元格字體居中對齊

設置單元格裡面找到左右與垂直全部點擊為居中就行了

⑵ poi Java生成excel合並單元格後字體居中

excel表格中合並的單元格內的字居中到兩行之間的位置:
1、選中合並後的單元格
2、在工具菜單欄選擇
格式
在下拉菜單選擇單元格
3、在單元格格式選項卡下面選擇對齊
4、在文本對齊方式中水平對齊
選擇居中,在垂直對齊下面選擇居中。確定。後單元格內的字就會居中到兩行之間的位置了。

⑶ java 中如何讓面板里的組件水平垂直居中。

我理解為你要垂直居中div裡面的元素: <div >{ ...... display:flex; justify-content:center; align-items:center; }</div>

⑷ 以下java程序,如何實現按鈕垂直排序,且按鈕大小不變。其他的實現不變。

進行容器的嵌套就能解決:

import javax.swing.*;
import java.awt.*;

public class Dashboard{
private static final long serialVersionUID = 1L;
JMenu m,m1;
JMenuBar mb;
public Dashboard(){
JFrame jf = new JFrame("Dashboard");
jf.setSize(700,300);
jf.setLocationRelativeTo(null);//窗口居中
jf.setBackground(Color.white);

m = new JMenu("File");
m1 = new JMenu("Help");
mb = new JMenuBar();
mb.add(m);
mb.add(m1);

JPanel Panel1 = new JPanel();
Panel1.setLayout(new GridLayout(5,3));
JLabel l1=new JLabel("");
JLabel l2=new JLabel("");
JLabel l3=new JLabel("");
JLabel l4=new JLabel("");
JLabel l5=new JLabel("");
JLabel l6=new JLabel("");
JLabel l7=new JLabel("");
JLabel l8=new JLabel("");
JLabel l9=new JLabel("");
JLabel l10=new JLabel("");
JLabel l11=new JLabel("");
JLabel l12=new JLabel("");
JLabel l13=new JLabel("");

JPanel Panel_left = new JPanel();
Panel_left.setBackground(Color.white);
Panel_left.setBorder(BorderFactory.createMatteBorder(5,5,5,10,Color.lightGray));

JPanel Panel_right = new JPanel();
Panel_right.setBackground(Color.white);
Panel_right.setBorder(BorderFactory.createMatteBorder(5,5,5,5,Color.lightGray));

JButton b_movementforecast = new JButton("Movement Forecast");
b_movementforecast.setPreferredSize(new Dimension(150, 40));

JButton b_yarddensity = new JButton("Yard Density");
b_yarddensity.setLocation(6, 60);
b_yarddensity.setPreferredSize(new Dimension(150, 40));

Panel1.add(l1);
Panel1.add(l2);
Panel1.add(l3);
Panel1.add(l4);
Panel1.add(b_movementforecast);
Panel1.add(l5);
Panel1.add(l6);
Panel1.add(l7);
Panel1.add(l8);
Panel1.add(l9);
Panel1.add(b_yarddensity);
Panel1.add(l10);
Panel1.add(l11);
Panel1.add(l12);
Panel1.add(l13);

Panel_left.add(Panel1);

jf.setJMenuBar(mb);
jf.getContentPane().add(Panel_left,"West") ;
jf.add(Panel_right);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
public static void main(String[] args){
new Dashboard();
}
}

⑸ 如何運用Java組件itext生成pdf

Controller層(param為數據)

byte[]bytes=PdfUtils.createPdf(param);
ByteArrayInputStreaminStream=newByteArrayInputStream(bytes);
//設置輸出的格式
response.setContentType("bin");
response.setHeader("content-disposition","attachment;filename="+URLEncoder.encode(itemName+"(評審意見).pdf","UTF-8"));
//循環取出流中的數據
byte[]b=newbyte[2048];
intlen;
while((len=inStream.read(b))>0)
response.getOutputStream().write(b,0,len);

inStream.close();

Service層(param為數據)

public static byte[] createPdf(Map<String,Object> param) {

byte[] result= null;

ByteArrayOutputStream baos = null;

//支流程評審信息匯總

List<CmplncBranchRvwInfoDTO> branchRvwInfos = (List<CmplncBranchRvwInfoDTO>) param.get("branchRvwInfos");

//主流程評審信息匯總

List<CmplncMainRvwInfoDTO> mainRvwInfos = (List<CmplncMainRvwInfoDTO>) param.get("mainRvwInfos");

//主評審信息

CmplncRvwFormDTO rvwFormDTO = (CmplncRvwFormDTO) param.get("rvwFormDTO");

//附件列表

List<FileInfoDTO> fileList = (List<FileInfoDTO>) param.get("fileList");

//專業公司

String legalEntityDeptDesc = (String) param.get("legalEntityDeptDesc");

String legalEntitySonDeptDesc = (String) param.get("legalEntitySonDeptDesc");

//設置頁邊距

Document doc = new Document(PageSize.A4, 20, 20, 60, 20);

try {

baos = new ByteArrayOutputStream();//構建位元組輸出流

PdfWriter writer = PdfWriter.getInstance(doc,baos);

//頁眉頁腳字體

BaseFont bf = null;

BaseFont bFont = null;

try {

bFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);

} catch (Exception e) {

e.printStackTrace();

}

Font footerFont = new Font(bFont, 10, Font.NORMAL);

Font title = new Font(bf,15,Font.BOLD);

Font content = new Font(bf,9,Font.NORMAL);

Font chinese = new Font(bf, 10, Font.BOLD);

/**

* HeaderFooter的第2個參數為非false時代表列印頁碼

* 頁眉頁腳中也可以加入圖片,並非只能是文字

*/

HeaderFooter header=new HeaderFooter(new Phrase("法律合規評審系統",title),false);

//設置是否有邊框等

header.setBorder(Rectangle.NO_BORDER);

header.setAlignment(1);

doc.setHeader(header);

HeaderFooter footer=new HeaderFooter(new Phrase("-",footerFont),new Phrase("-",footerFont));

/**

* 0左 1中 2右

*/

footer.setAlignment(1);

footer.setBorder(Rectangle.NO_BORDER);

doc.setFooter(footer);

doc.open();

//doc.add(new Paragraph("評審意見:",chinese));

//7列

PdfPTable table = new PdfPTable(7);

PdfPCell cell;

table.addCell(new Paragraph("評審項目編號",chinese));

table.addCell(new Paragraph(rvwFormDTO.getRvwItemCode(),content));

cell = new PdfPCell(new Paragraph("評審項目類型",chinese));

cell.setColspan(2);

table.addCell(cell);

String rvwItemParentType = (String) param.get("rvwItemParentType");

String rvwItemType = (String) param.get("rvwItemType");

String rvwItemTwoType = (String) param.get("rvwItemTwoType");

cell = new PdfPCell(new Paragraph(rvwItemParentType+"/"+rvwItemType+"/"+rvwItemTwoType,content));

cell.setColspan(3);

table.addCell(cell);

table.addCell(new Paragraph("申請人姓名",chinese));

table.addCell(new Paragraph(rvwFormDTO.getApplicantName(),content));

cell = new PdfPCell(new Paragraph("申請人所在部門",chinese));

cell.setColspan(2);

table.addCell(cell);

cell = new PdfPCell(new Paragraph(rvwFormDTO.getAplcntDeptName(),content));

cell.setColspan(3);

table.addCell(cell);

table.addCell(new Paragraph("錄入人姓名",chinese));

table.addCell(new Paragraph(rvwFormDTO.getRecordName(),content));

cell = new PdfPCell(new Paragraph("項目涉及金額",chinese));

cell.setColspan(2);

table.addCell(cell);

table.addCell(new Paragraph(String.valueOf(rvwFormDTO.getInvolveAmount()==null?0:rvwFormDTO.getInvolveAmount()),content));

table.addCell(new Paragraph("幣種",chinese));

String involveAmountType = (String) param.get("involveAmountType");

table.addCell(new Paragraph(involveAmountType,content));

table.addCell(new Paragraph("專業公司",chinese));

cell = new PdfPCell(new Paragraph(legalEntityDeptDesc+"->"+legalEntitySonDeptDesc,content));

cell.setColspan(6);

table.addCell(cell);

table.addCell(new Paragraph("項目名稱",chinese));

cell = new PdfPCell(new Paragraph(rvwFormDTO.getItemName(),content));

cell.setColspan(6);

table.addCell(cell);

table.addCell(new Paragraph("項目概述",chinese));

cell = new PdfPCell(new Paragraph(rvwFormDTO.getItemOverview(),content));

cell.setColspan(6);

table.addCell(cell);

table.addCell(new Paragraph("評審需求",chinese));

cell = new PdfPCell(new Paragraph(rvwFormDTO.getRvwDemand(),content));

cell.setColspan(6);

table.addCell(cell);

table.addCell(new Paragraph("申請人自我評估",chinese));

cell = new PdfPCell(new Paragraph(rvwFormDTO.getApplicantSelfAssmnt(),content));

cell.setColspan(6);

table.addCell(cell);

/* table.addCell(new Paragraph("同步抄送",chinese));

cell = new PdfPCell(new Paragraph(rvwFormDTO.getSyncsenderNames(),content));

cell.setColspan(6);

table.addCell(cell);*/

int infoNum = 0;

if(fileList.size() > 0){

//附件信息

cell = new PdfPCell(new Paragraph("附件信息",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

cell.setRowspan(fileList.size()+1);

table.addCell(cell);

//序號

cell = new PdfPCell(new Paragraph("序號",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//附件名稱

cell = new PdfPCell(new Paragraph("附件名稱",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//上傳時間

cell = new PdfPCell(new Paragraph("上傳時間",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//上傳人

cell = new PdfPCell(new Paragraph("上傳人",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//附件類型

cell = new PdfPCell(new Paragraph("附件類型",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//法律合規評審

cell = new PdfPCell(new Paragraph("法律合規評審",chinese));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

for (FileInfoDTO file : fileList) {

infoNum++;

//序號

cell = new PdfPCell(new Paragraph(infoNum+"",content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//附件名稱

cell = new PdfPCell(new Paragraph(file.getFileName(),content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//上傳時間

cell = new PdfPCell(new Paragraph(file.getUploadTimeFormat(),content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//上傳人

cell = new PdfPCell(new Paragraph(file.getUploadName(),content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//附件類型

String fileType;

if("1".equals(file.getFileType())){

fileType = "合同文件";

}else if("99".equals(file.getFileType())){

fileType = "支持文檔";

}else{

fileType = "";

}

cell = new PdfPCell(new Paragraph(fileType,content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//法律合規評審

String typeRvwStatus;

if("1".equals(file.getTypeRvwStatus())){

typeRvwStatus = "經審查附件無重大法律合規問題";

}else if("2".equals(file.getTypeRvwStatus())){

typeRvwStatus = "退回修改";

}else{

typeRvwStatus = "";

}

cell = new PdfPCell(new Paragraph(typeRvwStatus,content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

}

}else{

//附件信息

cell = new PdfPCell(new Paragraph("附件信息",chinese));

table.addCell(cell);

cell = new PdfPCell(new Paragraph("沒有附件",content));

cell.setColspan(6);

table.addCell(cell);

}

cell = new PdfPCell(new Paragraph("評審意見",chinese));

cell.setRowspan(mainRvwInfos.size()+branchRvwInfos.size());

//居中

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

if(mainRvwInfos.size()>0){

cell = new PdfPCell(new Paragraph("主評審意見",chinese));

cell.setRowspan(mainRvwInfos.size());

//居中

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

infoNum = 0;

for (CmplncMainRvwInfoDTO dto : mainRvwInfos) {

infoNum++;

//序號

cell = new PdfPCell(new Paragraph(infoNum+"",content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//評審意見

PdfPTable branchRvwInfosTable = new PdfPTable(1);

cell = new PdfPCell(new Paragraph(delHTMLTag(dto.getRvwOpinion()),content));

cell.disableBorderSide(2);

branchRvwInfosTable.addCell(cell);

//評審人和評審時間

cell = new PdfPCell(new Paragraph(dto.getRvwUmName()+"/"+getStringDate(dto.getRvwTime()),content));

cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

cell.disableBorderSide(1);

cell.setPaddingTop(5);

branchRvwInfosTable.addCell(cell);

PdfPCell branchRvwInfosCell = new PdfPCell(branchRvwInfosTable);

branchRvwInfosCell.setColspan(4);

table.addCell(branchRvwInfosCell);

}

doc.add(table);

}

if(branchRvwInfos.size()>0){

cell = new PdfPCell(new Paragraph("支評審意見",chinese));

cell.setRowspan(branchRvwInfos.size());

//居中

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

infoNum = 0;

for (CmplncBranchRvwInfoDTO dto : branchRvwInfos) {

infoNum++;

//序號

cell = new PdfPCell(new Paragraph(infoNum+"",content));

cell.setUseAscender(true);

cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中

cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中

table.addCell(cell);

//評審意見

PdfPTable branchRvwInfosTable = new PdfPTable(1);

cell = new PdfPCell(new Paragraph(delHTMLTag(dto.getRvwOpinion()),content));

cell.disableBorderSide(2);

branchRvwInfosTable.addCell(cell);

//評審人和評審時間

cell = new PdfPCell(new Paragraph(dto.getRvwUmName()+"/"+getStringDate(dto.getRvwTime()),content));

cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

cell.disableBorderSide(1);//隱藏上邊框

cell.setPaddingTop(5);

branchRvwInfosTable.addCell(cell);

PdfPCell branchRvwInfosCell = new PdfPCell(branchRvwInfosTable);

branchRvwInfosCell.setColspan(4);

table.addCell(branchRvwInfosCell);

}

doc.add(table);

}

if(doc != null){

doc.close();

}

result =baos.toByteArray();

} catch (DocumentException e) {

e.printStackTrace();

}finally{

if(baos != null){

try {

baos.close();

} catch (IOException e) {

log.error("PDF異常", e);

}

}

}

return result;

}

工具

/**

* 去掉HTML標簽

* @param htmlStr

* @return

*/

public static String delHTMLTag(String htmlStr){

if (htmlStr!=null){

String regEx_script="<script[^>]*?>[\s\S]*?<\/script>"; //定義script的正則表達式

String regEx_style="<style[^>]*?>[\s\S]*?<\/style>"; //定義style的正則表達式

String regEx_html="<[^>]+>"; //定義HTML標簽的正則表達式

Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);

Matcher m_script=p_script.matcher(htmlStr);

htmlStr=m_script.replaceAll(""); //過濾script標簽

Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);

Matcher m_style=p_style.matcher(htmlStr);

htmlStr=m_style.replaceAll(""); //過濾style標簽

Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);

Matcher m_html=p_html.matcher(htmlStr);

htmlStr=m_html.replaceAll(""); //過濾html標簽

Pattern p_enter = Pattern.compile("\s*| | | ");

Matcher m_enter = p_enter.matcher(htmlStr);

htmlStr = m_enter.replaceAll("");

}

return htmlStr.trim().replaceAll("&nbsp;", ""); //返迴文本字元串

}

/**

* @return返回字元串格式 yyyy-MM-dd HH:mm:ss

*/

public static String getStringDate(Date date) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(date);

return dateString;

}

⑹ poi Java生成excel合並單元格後字體居中

excel表格中合並的單元格內的字居中到兩行之間的位置:
1、選中合並後的單元格
2、在工具菜單欄選擇 格式 在下拉菜單選擇單元格
3、在單元格格式選項卡下面選擇對齊
4、在文本對齊方式中水平對齊 選擇居中,在垂直對齊下面選擇居中。確定。後單元格內的字就會居中到兩行之間的位置了。

⑺ java生成pdf如何讓文字和圖片顯示在同一行

可以用表格布局
BaseFont bf = BaseFont.createFont( "STSong-Light", "UniGB-UCS2-H", false, false, null, null);
Font fontChinese5 = new Font(bf,8);
PdfPTable table1 = new PdfPTable(2); //表格兩列
table1.setHorizontalAlignment(Element.ALIGN_CENTER); //垂直居中
table1.setWidthPercentage(100);//表格的寬度為100%
float[] wid1 ={0.75f,0.25f}; //兩列寬度的比例
table1.setWidths(wid1);
table1.getDefaultCell().setBorderWidth(0); //不顯示邊框

PdfPCell cell11 = new PdfPCell(new Paragraph("SilkRoad24 GmbH",fontChinese5)); table1.addCell(cell11);

String imagepath = "D:\\wl\\logo.png";
Image image = Image.getInstance(imagepath);
table1.addCell(image);
document.add(table1);//增加到文檔中

⑻ java導出PDF時候表格內容居中為什麼只實現左右居中,不能實現上下居中呢

再加上cell.setVerticalAlignment(cell.ALIGN_MIDDLE); 就可以了

閱讀全文

與java垂直居中相關的資料

熱點內容
壓縮因子定義 瀏覽:968
cd命令進不了c盤怎麼辦 瀏覽:214
葯業公司招程序員嗎 瀏覽:974
毛選pdf 瀏覽:659
linuxexecl函數 瀏覽:727
程序員異地戀結果 瀏覽:374
剖切的命令 瀏覽:229
干什麼可以賺錢開我的世界伺服器 瀏覽:290
php備案號 瀏覽:990
php視頻水印 瀏覽:167
怎麼追程序員的女生 瀏覽:487
空調外壓縮機電容 瀏覽:79
怎麼將安卓變成win 瀏覽:459
手機文件管理在哪兒新建文件夾 瀏覽:724
加密ts視頻怎麼合並 瀏覽:775
php如何寫app介面 瀏覽:804
宇宙的琴弦pdf 瀏覽:396
js項目提成計算器程序員 瀏覽:944
pdf光子 瀏覽:834
自拍軟體文件夾名稱大全 瀏覽:328