本文的目的是介绍为什么SWTComposite有时需要调用resize的详细情况,特别关注才能正确布局?的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解为什么SWTC
本文的目的是介绍为什么SWT Composite有时需要调用resize的详细情况,特别关注才能正确布局?的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解为什么SWT Composite有时需要调用resize的机会,同时也不会遗漏关于android-为什么findLastCompletelyVisibleItemPosition()返回-1?、Apache POI autoSizeColumn不正确resize、Apache POI autoSizeColumn()不能正常工作、c – 为什么sizeof引用类型给你的sizeof的类型?的知识。
本文目录一览:- 为什么SWT Composite有时需要调用resize()才能正确布局?
- android-为什么findLastCompletelyVisibleItemPosition()返回-1?
- Apache POI autoSizeColumn不正确resize
- Apache POI autoSizeColumn()不能正常工作
- c – 为什么sizeof引用类型给你的sizeof的类型?
为什么SWT Composite有时需要调用resize()才能正确布局?
有时,我们遇到一个SWT复合材料,它绝对拒绝正确布局自己。当我们在复合体上调用dispose然后将其替换为另一个时,常常会遇到这种情况。尽管似乎并不严格限于这种情况。
当我们遇到这个问题,约50%的时间,我们可以调用pack()
和layout()
对违规复合材料,并且一切都会好起来。但是,大约有50%的时间,我们必须这样做:
Point p = c.getSize();c.setSize(p.x+1, p.y+1);c.setSize(p);
布局管理器之类的每一种组合都曾经发生过这种情况。
我希望我有一个很好的,简单的,可复制的案例,但我没有。我希望有人会意识到这个问题,然后说:“嗯,你想念xyz…。”
答案1
小编典典在我看来, 布局的缓存已过时,需要刷新 。
SWT中的布局支持缓存,并且通常会缓存控件的首选大小,或者它们想要缓存的内容:
public abstract class Layout { protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache); protected boolean flushCache (Control control) {...} protected abstract void layout (Composite composite, boolean flushCache);}
我对SWT编程(以前的Swing程序员)比较陌生,但是遇到类似的情况,其中布局没有正确更新。我通常能够使用 其他
布局方法来解决它们,这也会导致布局刷新其缓存:
layout(boolean changed)layout(boolean changed, boolean allChildren)
android-为什么findLastCompletelyVisibleItemPosition()返回-1?
我正在尝试使用片段中的分页进行无休止的回收者视图.
但是面临的问题如下.
> findLastCompletlyVisibleItemPosition()或findFirstCompletelyVisibleItemPosition()仅返回-1.
>如果setnestedScrollingEnabled(false),则onScrollStateChanged不起作用
以下是我的代码示例. `
recyclerView = (RecyclerView) view.findViewById(R.id.recycler1);
//recyclerView.setnestedScrollingEnabled(false); // Smooth Scrolling
mLayoutManager = new linearlayoutmanager(getActivity());
lastVisiblePosition = mLayoutManager.findLastVisibleItemPosition();
firstVisibleItemPosition = mLayoutManager.findFirstCompletelyVisibleItemPosition();
Log.i("sandi", String.valueOf(firstVisibleItemPosition));
load = new LoadAdapter(getActivity(), grid_list);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(load);
mProgressDialog.dismiss();
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
int threshold =1;
int count = recyclerView.getChildCount();
Log.i("sand", String.valueOf(count));
if (newState == SCROLL_STATE_IDLE ) {
if (lastVisiblePosition >= count
- threshold) {
// Execute LoadMoreDataTask AsyncTask
Log.i("sand","stopped");
new LoadMoreDataTask().execute();
}
} else {
Log.i("sand","not stopped");
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
}
编辑
该问题的解决方案在评论部分.
解决方法:
在linearlayoutmanager中查看第1732至1747行
/**
* Returns the adapter position of the last fully visible view. This position does not include
* adapter changes that were dispatched after the last layout pass.
* <p>
* Note that bounds check is only performed in the current orientation. That means, if
* LayoutManager is horizontal, it will only check the view's left and right edges.
*
* @return The adapter position of the last fully visible view or
* {@link RecyclerView#NO_POSITION} if there aren't any visible items.
* @see #findLastVisibleItemPosition()
* @see #findFirstCompletelyVisibleItemPosition()
*/
public int findLastCompletelyVisibleItemPosition() {
final View child = findOneVisibleChild(getChildCount() - 1, -1, true, false);
return child == null ? NO_POSITION : getPosition(child);
}
如果child为null,则NO_POSITION为-1.
你在做什么:
在设置适配器之前,您正在拨打以下电话.没有可用的视图,因此您有-1.
lastVisiblePosition = mLayoutManager.findLastVisibleItemPosition();
firstVisibleItemPosition = mLayoutManager.findFirstCompletelyVisibleItemPosition();
您应该做什么:
当适配器的视图完全填充时,可以具有findLastVisibleItemPosition和findFirstCompletelyVisibleItemPosition.首先设置您的适配器,而不要像
load = new LoadAdapter(getActivity(), grid_list);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(load);
mProgressDialog.dismiss();
// adapter is set Now you may have your positions
lastVisiblePosition = mLayoutManager.findLastVisibleItemPosition();
firstVisibleItemPosition = mLayoutManager.findFirstCompletelyVisibleItemPosition();
Log.i("sandi", String.valueOf(firstVisibleItemPosition));
Apache POI autoSizeColumn不正确resize
我在Java中使用Apache POI创build一个Excel文件。 我填写数据然后尝试自动化每列,但大小总是错误的(我认为一致)。 前两行总是(?)完全折叠。 当我在Excel中自动调整列时,它完美的工作。
没有空白单元格正在写(我相信),resize是我做的最后一件事情。
下面是相关的代码:这是一个没有error handling等的简化版本
public static synchronized String storeResults(ArrayList<String> resultList,String file) { if (resultList == null || resultList.size() == 0) { return file; } FileOutputStream stream = new FileOutputStream(file); //Create workbook and result sheet XSSFWorkbook book = new XSSFWorkbook(); Sheet results = book.createSheet("Results"); //Write results to workbook for (int x = 0; x < resultList.size(); x++) { String[] items = resultList.get(x).split(PRIM_DELIM); Row row = results.createRow(x); for (int i = 0; i < items.length; i++) { row.createCell(i).setCellValue(items[i]); } } //Auto size all the columns for (x = 0; x < results.getRow(0).getPhysicalNumberOfCells(); x++) { results.autoSizeColumn(x); } //Write the book and close the stream book.write(stream); stream.flush(); stream.close(); return file; }
我知道这里有几个类似的问题,但其中大多数只是填充数据之前的大小的一个例子。 而less数不是更复杂/没有答案。
PHP执行shell命令权限被拒绝
本地开发,Apache与开发人员 – 文件权限
使用Apache Wsgi通过DJANGO_SETTINGS_MODULE环境variables设置Django设置文件
通过Apache上的IP地址限制请求?
使用Apache列入白名单的CORS
编辑:我尝试使用几个不同的字体,它没有工作。 这并不令人感到意外,因为不pipe字体是什么字体,都应该完全崩溃或不应该是。
另外,由于字体问题出现,我在Windows 7上运行该程序。
解决:这是一个字体问题。 我发现的唯一字体是Serif。
.htaccess规则:多个域到一个ssl域
PHP致命错误:require():无法解锁pthread锁
RewriteCond里的%N反向引用
URL缩短网站
mod-rewrite从url中删除文件夹名称
只是为了回应我的意见。 由于Java并不知道你想要使用这个链接的字体,因此如果你想把新的字体安装到Java中,你可以使用一些更好的东西。 它也有Java知道的默认字体的列表。
很高兴这有助于你解决了你的问题!
这可能与这个与Java Bug JDK-8013716相关的POI Bug相关:Calibri和Cambria字体的渲染器自更新45以来失败 。
在这种情况下,更改字体或使用6u45 / 7u21以上的JRE应该可以解决问题。
你也可以通过使用这样的代码来弥补这个问题,并避免列被完全折叠sheet.autoSizeColumn(x); if (sheet.getColumnWidth(x) == 0) { // autosize Failed use MIN_WIDTH sheet.setColumnWidth(x,MIN_WIDTH); } sheet.autoSizeColumn(x); if (sheet.getColumnWidth(x) == 0) { // autosize Failed use MIN_WIDTH sheet.setColumnWidth(x,MIN_WIDTH); }
我也遇到这个问题,这是我的解决方案。
脚步:
创建工作簿
创建电子表格
创建行
创建/设置字体“Arial”
用字体创建/设置样式
用值和样式创建/设置单元格
autoSizeColumn
创建文件
码:
// initialize objects XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet spreadsheet = workbook.createSheet(sheetName); XSSFRow row = spreadsheet.createRow(0); XSSFCell cell; // font/style XSSFFont font = workbook.createFont(); font.setFontName("Arial"); XSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); // create/set cell & style cell = row.createCell(0); cell.setCellValue("New Cell"); cell.setCellStyle(style); // auto size spreadsheet.autoSizeColumn(0); // create file File aFile = new File("Your Filename"); FileOutputStream out = new FileOutputStream(aFile); workbook.write(out);
资源:
http://www.tutorialspoint.com/apache_poi/index.htm
我在Windows 7上有类似的问题。
我使用Calibri字体(在我的JVM中支持)。 使用该字体时, autoSizeColumn() POI方法使用的java.awt.font.TextLayout的getBounds().getWidth()将返回0。
更改字体为Calibri-Regular解决了我的情况下的问题。
这是我的2美分 –
我使用默认的字体(在我的情况下宋体)使用它来使某些字段在XLS粗体。 像在Windows中的魅力一样工作,autoSizeColumn()函数。
Linux不是那么宽容。 自动调整大小是不合适的。 通过这个线程和其他我想出了以下解决方案。
我将Arial字体的.tff文件复制到JAVA / jre / lib / fonts目录中,然后重新运行该应用程序。 工作得很好。
我用Helvetica字体尝试替换Arial字体(实际上,Helvetica与Arial类似)。
XSSFFont font = wb.createFont(); font.setFontName("Helvetica");
当最宽的字符串以空格开始时,我发现自动调整大小没有使列宽足够,例如
cell.setCellValue(" New Cell");
这可以通过使用缩进来解决,例如
// font/style XSSFFont font = workbook.createFont(); font.setFontName("Arial"); XSSFCellStyle style = workbook.createCellStyle(); style.setFont(font); style.setIndention((short)2); // create/set cell & style cell = row.createCell(0); cell.setCellValue("New Cell"); cell.setCellStyle(style); // auto size spreadsheet.autoSizeColumn(0);
Apache POI autoSizeColumn()不能正常工作
我正在创build一个使用apache poi将信息写入excel文件的程序。 将所有数据input到文件后,我在文件的每一列调用autoSizeColumn方法。 但是它将列的大小调整为最后input的单元格的宽度,有时不像列中的其他单元格那么大。 我知道我正在使用它,不幸的是我现在没有互联网来发布任何代码,但我会尽快更新。
好吧,我希望我正在使用的代码标签,但这里是:
public void writeFile() { Workbook wb = new hssfWorkbook(); Sheet s = wb.createSheet(); try { FileOutputStream out = new FileOutputStream( this.getSelectedFile()); // create a new workbook // create a new sheet // declare a row object reference Row r = null; // declare a cell object reference Cell c = null; // in case of plain ascii wb.setSheetName(0,"Street Light Report"); // create a sheet with 30 rows (0-29) // int rownum; // short rownum; // PrintWriter printOut = new PrintWriter( // this.getSelectedFile()); String[] colName = { "Light Id","Flagged","Malfunction","Comments","Location","Date" }; // printOut.println("Light Id,Flagged,Malfunction,Comments,Location,Date"); Connections.connect(); String[][] data = Connections.searchForFlagged(); for (int i = 0; i < data.length; i++) { r = s.createRow(i); } r.setRowNum(0); for (int j = 0; j < 6; j++) { c = r.createCell(j); switch (j) { case 0: c.setCellValue(colName[j]); break; case 1: c.setCellValue(colName[j]); break; case 2: c.setCellValue(colName[j]); break; case 3: c.setCellValue(colName[j]); break; case 4: c.setCellValue(colName[j]); break; case 5: c.setCellValue(colName[j]); break; } } for (int i = 0; i < data.length; i++) { r.setRowNum(i + 1); for (int j = 0; j < data[i].length; j++) { c = r.createCell(j); // System.out.println(data[i][j]); switch (j) { case 0: c.setCellType(Cell.CELL_TYPE_NUMERIC); c.setCellValue(Integer.parseInt(data[i][j])); break; case 1: if (data[i][j].equals("true")) c.setCellValue("Yes"); else c.setCellValue("No"); break; case 2: if (data[i][j].equals("I")) c.setCellValue("Intermittent"); else c.setCellValue("Not Functional"); break; case 3: c.setCellValue(data[i][j]); break; case 4: c.setCellValue(data[i][j]); break; case 5: c.setCellValue(data[i][j]); break; } } } wb.getSheetAt(0).setPrintGridlines(true); for (int j = 0; j < 6; j++) { s.autoSizeColumn(j); } wb.write(out); out.close(); } catch (Exception ex) { } };
我会在这里张贴图片,但我需要代表。 点,我刚从这里开始。
**请注意,Connections类是JDBC类,以便java可以从MysqL数据库中获取信息,并返回string的二维数组**
jQuery.get没有收到服务器上的最新版本的文件
无法访问复制到/ var / www /或其他文件夹的PHP文件
添加过期标题没有mod_expires?
如果用户是移动的,如何重写到mobile.myUrl.com? (使用Apache或Webapp内?)
在docker文件中编辑conf文件
用户目录中的Apache CGI“报头之前的脚本输出结束”
Xampp – 安装sql Server和Visual Studio后无法启动Apache
如何在.htaccess文件中阻止来自多个引用者和子域的引荐stream量?
在linux中获取网站的状态码
将文件夹redirect到包含文件夹的子域
你只需要移动电话
sheet.autoSizeColumn(columnNumber);
数据添加完成后,在代码中添加一个点。
这里是一个API的链接
这是做到这一点的唯一方法。 我有同样的问题,我在输入数据之前调用方法autoSizeColumn() 。 跳它帮助
请注意,如果您正在生成巨大的报告s.autoSizeColumn(j); 会减慢性能。
移动for循环:
for (int j = 0; j < 6; j++) { s.autoSizeColumn(j); }
就在您写入工作簿并关闭您的外部对象之前。
wb.write(out);
总结
以上是小编为你收集整理的Apache POI autoSizeColumn()不能正常工作全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
c – 为什么sizeof引用类型给你的sizeof的类型?
When applied to a reference or a reference type,the result is the size of the referenced type.
这似乎与引用未指定的事实一致[dcl.ref](8.3.2.4):
It is unspecified whether or not a reference requires storage
但是,在语言中有这种矛盾似乎很奇怪.无论参考是否需要存储,能否确定参考使用的尺寸是否重要?看到这些结果似乎错了:
sizeof(vector<int>) == 24sizeof(vector<int>*) == 8sizeof(vector<int>&) == 24sizeof(reference_wrapper<vector<int>>) == 8
根据定义想要sizeof(T&)== sizeof(T)的原因是什么?
解决方法
引用的意图是对象本身的(别名);根据这个推理,他们都有相同的大小(和地址),这就是语言规定的意义.
抽象是泄漏的 – 有时引用有自己的存储,与对象分离,导致像您指出的异常.但是当我们需要处理一个“引用”作为对象的单独实体时,我们有指针.
今天的关于为什么SWT Composite有时需要调用resize和才能正确布局?的分享已经结束,谢谢您的关注,如果想了解更多关于android-为什么findLastCompletelyVisibleItemPosition()返回-1?、Apache POI autoSizeColumn不正确resize、Apache POI autoSizeColumn()不能正常工作、c – 为什么sizeof引用类型给你的sizeof的类型?的相关知识,请在本站进行查询。
本文标签: