Java Code Examples for javax.swing.JSlider#setAlignmentX()

The following examples show how to use javax.swing.JSlider#setAlignmentX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainWindow.java    From Creatures with GNU General Public License v2.0 4 votes vote down vote up
private void initUI(WorldView view) {
	JPanel rightContainer = new JPanel();
	rightContainer.setLayout(new BoxLayout(rightContainer, BoxLayout.PAGE_AXIS));

	textLabel = new JLabel("Creatures");
	textLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	speedLabel = new JLabel("Speed");
	speedLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	speedSlider = new JSlider(0, 15, 1);
	speedSlider.setAlignmentX(Component.LEFT_ALIGNMENT);
	speedSlider.setMajorTickSpacing(5);
	speedSlider.setMinorTickSpacing(1);
	speedSlider.setSnapToTicks(true);
	speedSlider.setPaintLabels(true);
	speedSlider.setPaintTicks(true);
	speedSlider.addChangeListener(this);
	
	JPanel maxFoodContainer = new JPanel();
	maxFoodContainer.setLayout(new FlowLayout(FlowLayout.LEFT));
	maxFoodContainer.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	maxFoodLabel = new JLabel("Max Food");
	SpinnerModel maxFoodSpinnerModel = new SpinnerNumberModel(WorldModel.maxFoodAmount, 0, 100000, 1);
	maxFoodSpinner = new JSpinner(maxFoodSpinnerModel);
	maxFoodSpinner.setEditor(new JSpinner.NumberEditor(maxFoodSpinner, "#"));
	maxFoodSpinner.addChangeListener(this);
	
	maxFoodContainer.add(maxFoodLabel);
	maxFoodContainer.add(maxFoodSpinner);
	
	rightContainer.add(textLabel);
	rightContainer.add(Box.createVerticalStrut(10));
	rightContainer.add(speedLabel);
	rightContainer.add(speedSlider);
	rightContainer.add(maxFoodContainer);

	splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, view, rightContainer);
	splitPane.setResizeWeight(0.8);

	add(splitPane);
	
	menuBar = new JMenuBar();
	
	fileMenu = new JMenu("File");
	exportStatisticsItem = new JMenuItem("Export Statistics");
	exportStatisticsItem.addActionListener(this);
	closeItem = new JMenuItem("Close");
	closeItem.addActionListener(this);
	fileMenu.add(exportStatisticsItem);
	fileMenu.addSeparator();
	fileMenu.add(closeItem);
	
	worldMenu = new JMenu("Creation");
	createWorldItem = new JMenuItem("Create World");
	createWorldItem.addActionListener(this);
	worldMenu.add(createWorldItem);
	worldMenu.addSeparator();
	createCreatureItem = new JMenuItem("Create Creature");
	createCreatureItem.addActionListener(this);
	worldMenu.add(createCreatureItem);
	createCreaturesItem = new JMenuItem("Create Creatures");
	createCreaturesItem.addActionListener(this);
	worldMenu.add(createCreaturesItem);
	
	statisticsMenu = new JMenu("Statistics");
	showStatisticsItem = new JMenuItem("Show Statistics");
	showStatisticsItem.addActionListener(this);
	statisticsMenu.add(showStatisticsItem);
	
	menuBar.add(fileMenu);
	menuBar.add(worldMenu);
	menuBar.add(statisticsMenu);
	
	setJMenuBar(menuBar);
}
 
Example 2
Source File: DeobfuscationDialog.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public DeobfuscationDialog() {
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    setSize(new Dimension(330, 270));
    setTitle(translate("dialog.title"));
    Container cp = getContentPane();
    cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
    codeProcessingLevel = new JSlider(JSlider.VERTICAL, 1, 3, 3);
    codeProcessingLevel.setMajorTickSpacing(1);
    codeProcessingLevel.setPaintTicks(true);
    codeProcessingLevel.setMinorTickSpacing(1);
    codeProcessingLevel.setSnapToTicks(true);
    JLabel lab1 = new JLabel(translate("deobfuscation.level"));
    //lab1.setBounds(30, 0, getWidth() - 60, 25);
    lab1.setAlignmentX(0.5f);
    cp.add(lab1);
    Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
    //labelTable.put(LEVEL_NONE, new JLabel("None"));

    labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_DEAD_CODE.getLevel(), new JLabel(translate("deobfuscation.removedeadcode")));
    labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_TRAPS.getLevel(), new JLabel(translate("deobfuscation.removetraps")));
    labelTable.put(DeobfuscationLevel.LEVEL_RESTORE_CONTROL_FLOW.getLevel(), new JLabel(translate("deobfuscation.restorecontrolflow")));
    codeProcessingLevel.setLabelTable(labelTable);

    codeProcessingLevel.setPaintLabels(true);
    codeProcessingLevel.setAlignmentX(Component.CENTER_ALIGNMENT);
    //codeProcessingLevel.setSize(300, 200);

    //codeProcessingLevel.setBounds(30, 25, getWidth() - 60, 125);
    codeProcessingLevel.setAlignmentX(0.5f);
    add(codeProcessingLevel);
    //processAllCheckbox.setBounds(50, 150, getWidth() - 100, 25);
    processAllCheckbox.setAlignmentX(0.5f);
    add(processAllCheckbox);

    processAllCheckbox.setSelected(true);

    JButton cancelButton = new JButton(translate("button.cancel"));
    cancelButton.addActionListener(this::cancelButtonActionPerformed);
    JButton okButton = new JButton(translate("button.ok"));
    okButton.addActionListener(this::okButtonActionPerformed);

    JPanel buttonsPanel = new JPanel(new FlowLayout());
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    buttonsPanel.setAlignmentX(0.5f);
    cp.add(buttonsPanel);

    setModal(true);
    View.centerScreen(this);
    setIconImage(View.loadImage("deobfuscate16"));
}