也发布在coderanch.com上.
import javax.swing.*;
public class Tmp {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JTextField());
frame.setVisible(true);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
有关调整此JFrame大小的问题.
这是程序启动后默认的外观:

当我尝试像在图片上显示的那样调整大小并将鼠标指针移动到屏幕顶部时(如下图所示)我看到了:

当我释放鼠标时,框架被调整大小但没有响应.它上面有一个黑色的空间.这是它的样子:

这种情况发生在Windows 8.1和java 1.7.0_45上(它也发生在Windows 7上).
使用其他方法在Windows中调整框架大小时不会发生此问题.
仅当"在拖动时显示窗口内容"在系统设置中处于活动状态时才会发生.
为什么会这样?
怎么解决这个问题?
如何以编程方式设置NSView的大小,例如
-(void)awakeFromNib {
self.frame.size.width = 1280; // Does nothing...
self.frame.size.height = 800; // ...neither does this.
...
Run Code Online (Sandbox Code Playgroud)
nib(Mac OSX)中的大小设置工作正常,但我想在代码中执行此操作.
我正在进行流体布局项目.我的文档中有一些固定高度的DIV,所有这些都有不同的高度.我需要在浏览器调整大小时按比例更改这些DIV的高度.这是标记.
<body>
<div id="a" class="target"></div>
<div id="b" class="target"></div>
<div id="c" class="target"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
和css:
<style>
body { width: 90%; margin: 0 auto;}
.target { width:30%; float:left; margin:1.6%; cursor:pointer; }
#a { height: 200px; background-color: yellow;}
#b { height: 400px; background-color: green;}
#c { height: 600px; background-color: grey;}
</style>
Run Code Online (Sandbox Code Playgroud)
听起来很简单!主要条件是我不知道预定量的目标DIV及其ID,这就是我使用.each(function())的原因.这是我写的脚本:
$(document).ready(function(){
//set the initial body width
var originalWidth = 1000;
/*I need to go through all target divs because i don't know
how many divs are here and what are …Run Code Online (Sandbox Code Playgroud) 一个JavaScript问题.
有人知道为什么在window.onresize页面加载时会在某些浏览器中调用它吗?
这可以避免吗?
我发现了IE中的问题,Android 27的Firefox 27(三星Galaxy S3上测试),Google Nexus 7(浏览Browserstack)和Windows Phone 8(Internet Explorer).
我的testpage看起来像这样:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script type="text/javascript">
window.onresize = resize;
function resize(){
alert("resize event detected!");
}
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
解:
var windowWidth = $(window).width();
window.onresize = resize;
function resize(){
if($(window).width()!=windowWidth){
alert("Bingo");
windowWidth = $(window).width();
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在页面加载后更改截面高度,但它并不总是有效.我知道我的代码更改高度很好,它适用于窗口调整大小,只是在document.ready之后的初始调用并不总是有效.
var $window = $(window);
function wrap_element_link_mobile(object, path) {
if ($(this).width() < 921 && !object.parent().is('a')) {
object.wrap("<a href='" + path + "'></a>");
} else if ($(this).width() > 920 && object.parent().is('a')) {
object.unwrap();
}
}
function resize_section() {
var sectionMinHeight = $(window).height() - $('header').height() - $('footer').height() - 7;
$('section').css('min-height', sectionMinHeight);
}
/* Called after document Load
================================ */
$(document).ready(function () {
var $mainLogo = $('#main-logo');
wrap_element_link_mobile($mainLogo, '/');
resize_section();
$window.resize(function () {
wrap_element_link_mobile($mainLogo, '/');
resize_section();
});
});
Run Code Online (Sandbox Code Playgroud)
在初始调用中创建了一个console.log后,我发现它已被调用但由于某种原因它无效.
*编辑我看到的屏幕

注意滚动条,如果我完全调整窗口大小,它会消失并且是适当的高度.
我正在编写一个小程序,其目的是在窗口大小更改时运行调整大小方法。为此,我使用了toplevel.bind("<Configure>", self.resize). 虽然这确实适用于调整大小,但该方法会被调用数百次:滚动时、使用某些按钮时,即使窗口大小不会因任何这些操作而改变。如何绑定事件,以便仅在更改窗口大小时调用它?
import tkinter as tk
def resize(event):
print("widget", event.widget)
print("height", event.height, "width", event.width)
parent = tk.Toplevel()
canvas = tk.Canvas(parent)
scroll_y = tk.Scrollbar(parent, orient="vertical", command=canvas.yview)
scroll_x = tk.Scrollbar(parent, orient="horizontal", command=canvas.xview)
frame = tk.Frame(canvas)
# put the frame in the canvas
canvas.create_window(0, 0, anchor='nw', window=frame)
# make sure everything is displayed before configuring the scrollregion
canvas.update_idletasks()
canvas.configure(scrollregion=canvas.bbox('all'),
yscrollcommand=scroll_y.set,
xscrollcommand=scroll_x.set)
scroll_y.pack(fill='y', side='right')
scroll_x.pack(fill='x', side='bottom')
canvas.pack(fill='both', expand=True, side='left')
parent.bind("<Configure>", resize)
parent.mainloop()
Run Code Online (Sandbox Code Playgroud)
输出:
widget .!toplevel
height 200 width 200
widget .!toplevel.!scrollbar …Run Code Online (Sandbox Code Playgroud) 我有一个没有标题栏的窗口(WindowStyle == WindowStyle.None).整个窗口使用Aero玻璃效果.当我使窗口不可靠(ResizeMode == ResizeMode.NoResize)时,玻璃效果消失,我的控件只悬挂在半空中.(基本上,窗口本身会消失,但会留下内容.)
有没有办法让我在不摆脱窗框的情况下使窗户不可靠?
我已经阅读了在无边界WPF窗口上启用Vista玻璃效果的问题,但这不是我想要的 - 我想保持窗口边框.有关我希望窗口看起来像什么的示例,请在启用Aero的情况下点击Alt + Tab.
为了澄清,我不希望将鼠标悬停在窗口边框上时显示调整大小的游标.这基本上就是我希望我的窗口看起来像:
投影仪http://i37.tinypic.com/2mg4jty.png
解决方案不一定是严格的WPF - 我很好地使用Win32 API进行攻击以实现此目的.
我有一个NSViewController名字Hardness,我不需要让用户调整它.当然,我可以在每次用户尝试时重新调整它,但有没有办法让用户打开一个窗口全屏,或者拉伸窗口?
每当我调整GLFW窗口大小时,在调整窗口大小时都不会绘制。我调整窗口大小后,才可以绘制窗口新暴露的部分。您可以在下面的图片中自己看到它:

这是我的应用程序的代码。我在Visual Studio 2015上运行Windows 10
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
void get_resolution(int* window_width, int* window_height);
void initGlfwSettings();
GLFWwindow* initGlfwWindow();
void initGlad();
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main()
{
initGlfwSettings();
GLFWwindow* window = initGlfwWindow();
initGlad();
// glad: load all OpenGL function pointers
// ---------------------------------------
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
int width, height;
glfwGetWindowSize(window, &width, &height);
glClearColor(0.2f, 0.3f, …Run Code Online (Sandbox Code Playgroud) 如果有人可以提供帮助,我有一个自定义钩子,它使用 ResizeObserver 来更改组件的宽度。我的问题是,当我去运行我的单元测试时,它破坏了我的所有测试,查看快照时它没有渲染 dom 中的所有元素。在我实现 ResizeObserver 之前,它一直在工作。有谁知道我是否有一种方法可以开玩笑。将 ResizeObserver 模拟为未定义。或者其他建议。
import * as React from 'react';
import ResizeObserver from 'resize-observer-polyfill';
const useResizeObserver = (ref: { current: any }) => {
const [dimensions, setDimensions] = React.useState<DOMRectReadOnly>();
React.useEffect(() => {
const observeTarget = ref.current;
const resizeObserver = new ResizeObserver((entries) => {
entries.forEach((entry) => {
setDimensions(entry.contentRect);
});
});
resizeObserver.observe(observeTarget);
return () => {
resizeObserver.unobserve(observeTarget);
};
}, [ref]);
return dimensions;
};
export default useResizeObserver;
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from …Run Code Online (Sandbox Code Playgroud) unit-testing window-resize reactjs jestjs react-testing-library