小编Ade*_*ros的帖子

如何获得JPanel引入的边距

我有一个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)

更新:

  1. 我的JTree 已经在JScrollPane中了
  2. 我的JScrollPane在Jpanel中

java swing jpanel

1
推荐指数
1
解决办法
86
查看次数

这个c ++代码有什么问题?

正如你所看到的,我是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++

0
推荐指数
1
解决办法
244
查看次数

为什么类型扣除不能按预期工作?

我对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()中

c++ metaprogramming type-deduction

0
推荐指数
1
解决办法
112
查看次数

答案总是0

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)

java

0
推荐指数
1
解决办法
218
查看次数

为什么ObjectOutputStream.writeObject在写字节数组时比写字节更快?

我做了一个小的基准测试,发现ObjectOutputStream.writeObject速度比ObjectOutputStream.write(byte[] bytes)我快,但我似乎无法找到可能的解释,因为在引擎盖下,writeObjectObjectOutputStream.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)

java objectoutputstream

0
推荐指数
1
解决办法
495
查看次数