我有一个JPanel 面板,其中包含一个JTree 树.有时,JTree的宽度或高度大于面板本身的宽度或高度.
我想要做的是使用面板的高度和宽度重新计算树的高度和宽度.唯一的问题是我不知道如何获得JPanel引入的边距,以便精确计算JTree的新大小.
我想要的例子:
if (treeHeight >= panelSize.getHeight()) {
treeHeight = panelSize.getHeight() - panelMargins; // panelMargins is what I don't know how to calculate
}
Run Code Online (Sandbox Code Playgroud)
更新:
正如你所看到的,我是C++的新手,但我无法理解为什么y = new Person()函数foo是错误的.谢谢你的帮助.
我收到这个错误:
错误:'y =(((Person*)operator new(32u)),(,)中的'operator ='不匹配)''
我将接受今晚最赞成的答案或更有说服力的答案.
我和我的朋友之间的争论是foo函数可以改变对象并在函数之外传播更改,就像在做的时候一样y = Person(),然后brother也会改变它还是会保持原样?
.
#include <iostream>
using namespace std;
class Person {
public:
int age;
char name[25];
Person() {
age = 0;
}
};
void foo(Person &y)
{
y = new Person();
}
int main()
{
Person *brother = new Person();
brother->age = 20;
cout << "age = " << brother->age << endl;
foo(*brother);
cout << "age = " << …Run Code Online (Sandbox Code Playgroud) 我对C++元编程中的类型推导有一个小问题.有一定的功能做一些动作.
main.cpp中
template<typename T> void foo(T arg) {
// do some action on argument
std::cout << typeid(arg).name() << std::endl;
}
int main(int argc, char** argv) {
int array[100] = {0};
std::cout << typeid(array).name() << std::endl;
foo(array);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
A100_i
Pi
Run Code Online (Sandbox Code Playgroud)
为什么精氨酸在函数foo的()具有比另一种数据类型数组函数main()中?
import java.io.*;
class empl
{
int p, n, r, i;
void accept()
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Principal amount");
int p = Integer.parseInt(br.readLine());
System.out.println("Enter no of years");
int n = Integer.parseInt(br.readLine());
System.out.println("Enter rate");
int r = Integer.parseInt(br.readLine());
} catch(Exception e)
{
System.out.println("" + e);
}
}
int calculate()
{
i = (p * n * r) / 100;
return (i);
}
}
class bank
{
public static void main(String args[])
{
empl e = new …Run Code Online (Sandbox Code Playgroud) 我做了一个小的基准测试,发现ObjectOutputStream.writeObject速度比ObjectOutputStream.write(byte[] bytes)我快,但我似乎无法找到可能的解释,因为在引擎盖下,writeObject将ObjectOutputStream.write(byte[] bytes)间接调用
测试代码
public static void main(String[] args) throws Exception {
byte[] bytes = new byte[10000];
for (int i = 0; i < 10000; ++i) {
bytes[i] = (byte) (i % 256);
}
ByteArrayOutputStream out2 = new ByteArrayOutputStream();
try(ObjectOutputStream ostream2 = new ObjectOutputStream(out2)) {
for (int i = 0; i < 10000; ++i) {
ostream2.writeInt(bytes.length);
ostream2.write(bytes, 0, bytes.length);
}
out2.reset();
long start = System.nanoTime();
for (int i = 0; i < …Run Code Online (Sandbox Code Playgroud)