小编Dan*_*Dan的帖子

比较者违反一般合同

以下代码是Dave Koelle的AlphanumComparator的编辑版本.编辑包含将空字符串排序到列表末尾的代码,或者JTable在我的情况下的底部.问题java.lang.IllegalArgumentException: Comparison method violates its general contract!出现了.

为了解决我的问题,我调查了它,发现比较器没有return 0;正确位置的原因.我还发现在Java注释bug数据库全文

java.util.Arrays.sort和(间接)java.util.Collections.sort使用的排序算法已被替换.如果新的排序实现检测到违反Comparable合同的Comparable,则可能抛出IllegalArgumentException.以前的实现默默地忽略了这种情况.如果需要以前的行为,则可以使用新的系统属性java.util.Arrays.useLegacyMergeSort来恢复以前的mergesort行为

import java.util.Comparator;
import javax.swing.JTable;
import javax.swing.SortOrder;

public class AlphanumComparator implements Comparator<String> {
    JTable table;

    public AlphanumComparator(JTable table) {
        this.table = table;
    }

    private final boolean isDigit(char ch) {
        return ch >= 48 && ch <= 57;
    }

    private final String getChunk(String s, int slength, int marker) {
        StringBuilder chunk = new StringBuilder();
        char c = s.charAt(marker);
        chunk.append(c);
        marker++;
        if …
Run Code Online (Sandbox Code Playgroud)

java sorting comparator

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

这和超级java

this并且super是关键字不是他们; 那么我如何使用它们以与方法相同的方式将参数传递给构造函数?总之,两者都能表现出如此独特的行为?

java

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

如果不应该,Choco会将变量强制为true

我对Choco和CP完全不熟悉,但是我正在制作一个小模型来解决Steiner树问题,而Choco一直强迫第一个节点无论图形是什么(并且它不正确,我检查过).

我有一个esIntVar 数组,如果边缘在解决方案中== 1,否则== 0.对于vs设置顶点的数组也是如此.我使用数组activeEdgeW能够有一个标量约束,其中coeffs是可变的.然后我只有通道约束,树约束和sum == w约束.并尽量减少w.相当简单,但由于某种原因vs[0] == true总是,任何图形.

我的模型老实说非常简单,我真的不知道它来自哪里:

    s = new Solver("Solver");
    vs = VF.boolArray("vs", nbV, s);
    es = VF.boolArray("es", nbE, s);
    w = VF.integer("w", 0, maxW, s);

    IntVar[] activeEdgeW = new IntVar[nbE];
    for(int i = 0; i < nbE; i++) { 
        activeEdgeW[i] = VF.enumerated("activeEdgeW["+i+"]", new int[]{0,ws[i]}, s); //Weight is either 0 or ws[i]
        ICF.arithm(activeEdgeW[i], "=", ws[i]).reifyWith(es[i]); //weight of edge is ws[i] if edge is in, 0 otherwise
    }


    UndirectedGraph …
Run Code Online (Sandbox Code Playgroud)

java constraint-programming choco

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

检测何时将数据添加到文档中,例如.一个角色或白色空间

有没有办法检测用户何时使用VBA在Microsoft Word中按键.我已经搜索过这样做的方法.我还搜索了一些方法,这些方法可以解决这个问题,例如检测插入点何时移动,或者检测到新单词放在word文档中的时间,但我一直没看.我目前正在使用,appWord_WindowSelectionChange(ByVal Sel As Selection)但在您键入时无法检测到.

我很感激有人向我展示如何检测按键,或者能够向我展示一个可以实现相同目标的解决方法.

编辑

如果上面我想要的内容摘要不清楚,我道歉.我所拥有的是一个使用它的子appWord_WindowSelectionChange(ByVal Sel As Selection).然而,我想要的是,只要在word文档中输入任何数据,就会触发此子目录,例如.一个字母或一个空白字符.例如,如果单词文档的页脚中存在字符计数,并且我已更新此字符计数,则字符计数字段应在用户键入文档时更新.

vba ms-word word-vba

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

允许嵌套的JSplitPanes控制父JSplitPanes

下面是使用多个嵌套创建的简单布局的代码JSplitPanes.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class CDBurner extends JFrame {
    private static final long serialVersionUID = -6027473114929970648L;
    JSplitPane main, folder, rest;
    JPanel centeral, folders, favourites, tasks;
    JLabel label;

    private CDBurner() {
        super("Dan's CD Burner");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridLayout(1, 1));
        getContentPane().setBackground(Color.black);

        createLayout();

        pack();
        setMinimumSize(getSize());
        setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
        setVisible(true);
        requestFocus();
    }

    private void createLayout() {
        createPanels();
        rest = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, centeral, tasks);
        rest.setResizeWeight(1);
        rest.setContinuousLayout(true);
        rest.setOneTouchExpandable(true);
        folder = new JSplitPane(JSplitPane.VERTICAL_SPLIT, favourites, …
Run Code Online (Sandbox Code Playgroud)

java swing jsplitpane

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

Unity 2019 中包的版本控制

Packages我正在 git 中管理我的 Unity 2019.3 项目,并且我的项目根目录中有一个名为的目录。这里有一个名为manifest.json. 这是文件夹中唯一重要的文件,还是还有其他可以生成并需要跟踪的配置文件?

换句话说,将以下几行放入我的中是否安全?.gitignore

/[Pp]ackages/*
!/[Pp]ackages/manifest.json
Run Code Online (Sandbox Code Playgroud)

这与这个问题非常相似,但它没有明确回答我想知道的内容。


编辑

为了澄清,我问的是是否manifest.json总是足以重新生成包的内容,或者是否可能有其他文件存储在其中并需要配置。如果由 Unity 自动重新生成,即文件将不一样。

其用途是我有一个资产,可以将文件添加到该 Packages 文件夹中,并且它们不需要跟踪。当需要时,它们会被资产自动添加回来。所以我想从该文件夹中排除除必要文件之外的所有文件。如果必要的文件可能会发生变化,并且我无法知道可以生成哪些配置文件,那么我不会这样做。如果manifest.json始终是该文件夹中唯一重要的文件,我将保持.gitignore原样。

git version-control unity-game-engine

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

gRPC keeping response streams open for subscriptions

I've tried to define a gRPC service where client can subscribe to receive broadcasted messages and they can also send them.

syntax = "proto3";

package Messenger;

service MessengerService {
    rpc SubscribeForMessages(User) returns (stream Message) {}
    rpc SendMessage(Message) returns (Close) {}
}

message User {
    string displayName = 1;
}

message Message {
    User from = 1;
    string message = 2;
}

message Close {}
Run Code Online (Sandbox Code Playgroud)

My idea was that when a client requests to subscribe to the messages, the response stream …

c# .net-core grpc

6
推荐指数
2
解决办法
2554
查看次数

自动重新调整GridBagLayout中的组件大小

在这段代码中,我有一个面板,GridBagLayout其中包含a JLabel和a JTextField.

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

public class Simple
{
    JFrame simpleWindow = new JFrame("Simple MCVE");

    JPanel  simplePanel = new JPanel();

    JLabel lblSimple;
    JTextField txtSimple;

    public void numberConvertGUI()
    {
        simpleWindow.setBounds(10, 10, 420, 80);

        simpleWindow.setMinimumSize(new Dimension(420, 80));

        simpleWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        simpleWindow.setLayout(new GridLayout(1,1));

        createSimplePanel();

        simpleWindow.getContentPane().add(simplePanel);

        simpleWindow.setVisible(true);
    }

    public void createSimplePanel()
    {
        simplePanel.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        lblSimple = new JLabel();
        c.weightx = 0.0;
        c.weighty = 1.0;
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(0,2,0,2);
        c.gridx = 0;
        c.gridy …
Run Code Online (Sandbox Code Playgroud)

java swing layout-manager autoresize gridbaglayout

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

XAML TabControl边界问题

我试图制作一个TabControl支持滚动的自定义,但保持原始的外观和感觉TabControl,显然除了它滚动.

首先,我选择编辑所用原始模板的副本TabControl.

然后我把ScrollViewer周围TabPanel.但是,这会导致一个小问题,即选中时标签现在在其底部有一个边框.通过比较图像中的法线TabControl和样式TabControl,可以看到这一点.

起初我假设这是滚动查看器的z索引,但在尝试不同的值并确保滚动查看器的z索引并且TabPanel明显高于Border'sz索引之后,它没有任何区别.

如果选中的选项卡底部没有边框,如何将其包裹在ScrollViewer?中,我怎样才能达到相同的效果?

在此输入图像描述


MainWindow.xaml

<Window x:Class="ScrollableTabControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
        <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/>
        <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}">
            <Setter Property="Padding" Value="2"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Background" Value="{StaticResource TabItem.Selected.Background}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TabItem.Selected.Border}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid x:Name="templateRoot" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml border

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

没有焦点的ComboBoxItem

我正在处理ComboBox通常包含大量数据的元素; ~250000个数据条目.

当a ComboBox设置有点像这样时,这很好用.

<ComboBox ItemsSource="{Binding Items}">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

但是,ComboBox我正在使用的一些自定义修改要求ComboBoxItem元素不可聚焦.我通过使用中的setter实现了这一点ComboBox.ItemContainerStyle.

<ComboBox ItemsSource="{Binding Items}">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter
                Property="Focusable"
                Value="False" />
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

但这有一个问题.它可以正常工作,直到选择了一个对象.然后当用户ComboBox再次尝试打开时,它会使程序崩溃.

我的问题是,如何ComboBox设置所有ComboBoxItem元素都不可调焦,但它不会使程序崩溃.


问题的GIF


示例代码

XAML

<Window x:Class="FocusableTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="MainWindow"
        Height="450"
        Width="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="2*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions> …
Run Code Online (Sandbox Code Playgroud)

c# wpf

5
推荐指数
2
解决办法
290
查看次数