Java Code Examples for javax.swing.JPanel#setPreferredSize()

The following examples show how to use javax.swing.JPanel#setPreferredSize() . 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: AdditionalWizardPanel.java    From netbeans with Apache License 2.0 8 votes vote down vote up
/** Gets component to display. Implements superclass abstract method. 
 * @return <code>AdditionalPanel</code> instance */
protected Component createComponent() {
    JPanel panel = new JPanel();
    
    //Accessibility
    panel.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(AdditionalWizardPanel.class).getString("ACS_AdditionalWizardPanel"));                    
    
    panel.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, Integer.valueOf(2));
    panel.setName(NbBundle.getBundle(getClass()).getString("TXT_ModifyAdditional"));
    panel.setPreferredSize(I18nWizardDescriptor.PREFERRED_DIMENSION);

    panel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    panel.add(getUI(), constraints);
    
    return panel;
}
 
Example 2
Source File: UI.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
public static JPanel createQueryResultPanel(DefaultTableModel tblQueryResultModel) {
  JPanel queryPanel = new JPanel();
  queryPanel.setMaximumSize(new Dimension(1000, 200));
  queryPanel.setPreferredSize(new Dimension(1000, 200));
  queryPanel.setLayout(new BoxLayout(queryPanel, BoxLayout.Y_AXIS));
  queryPanel.setVisible(true);
  
  final JTable tblQueryResult = new JTable(tblQueryResultModel);
   /* tblQueryResult.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    
    @Override
    public void valueChanged(ListSelectionEvent e) {
      int row = tblQueryResult.getSelectedRow();
      Point g = (Point) tblQueryResultModel.getValueAt(row, 4);
      map.zoomTo(g);
    }
  });*/
    
    JScrollPane tblQueryScrollPane = new JScrollPane(tblQueryResult);
    //tblQueryScrollPane.getViewport().setBackground(UI.COLOR_PURPLE);
    queryPanel.add(tblQueryScrollPane);
    
  return queryPanel;
}
 
Example 3
Source File: JythonREPLSlide.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	final JythonInterpreter interpreter = new JythonInterpreter();

	final JConsole console = new JConsole(interpreter.getInputStream(), interpreter.getOutputStream());
	console.setPythonMode();
	base.add(console);

	new Thread(interpreter).start();

	return base;
}
 
Example 4
Source File: CombinedCategoryPlotDemo1.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new demo instance.
 *
 * @param title  the frame title.
 */
public CombinedCategoryPlotDemo1(String title) {
    super(title);
    JPanel chartPanel = createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}
 
Example 5
Source File: CheckPolyCubicBezierCurve2D.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final static void main(String[] args){
	JPanel panel = new CheckPolyCubicBezierCurve2D();
	JFrame frame = new JFrame("Check Poly Bezier Curve");
	panel.setPreferredSize(new Dimension(400, 400));
	frame.setContentPane(panel);
	frame.pack();
	frame.setVisible(true);
}
 
Example 6
Source File: ButtonBarMain.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
private JPanel makePanel(String title) {
  JPanel panel = new JPanel(new BorderLayout());
  JLabel top = new JLabel(title);
  top.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
  top.setFont(top.getFont().deriveFont(Font.BOLD));
  top.setOpaque(true);
  top.setBackground(panel.getBackground().brighter());
  panel.add("North", top);
  panel.setPreferredSize(new Dimension(400, 300));
  panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
  return panel;
}
 
Example 7
Source File: CheckDrawRectangles2D.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final static void main(String[] args){
	System.out.println("draw rectangles");
	
	JPanel panel = new CheckDrawRectangles2D();
	panel.setPreferredSize(new Dimension(600, 500));
	JFrame frame = new JFrame("Draw rectangles");
	frame.setContentPane(panel);
	frame.pack();
	frame.setVisible(true);		
}
 
Example 8
Source File: CheckReflectedBoundary2D.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final static void main(String[] args){
	System.out.println("draw a clipped boundary");
	
	JPanel panel = new CheckReflectedBoundary2D();
	JFrame frame = new JFrame("Draw a clipped boundary");
	panel.setPreferredSize(new Dimension(500,400));
	frame.setContentPane(panel);
	frame.pack();
	frame.setVisible(true);
	
}
 
Example 9
Source File: CheckGeneralPath2D_Clip.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final static void main(String[] args){
	JPanel panel = new CheckGeneralPath2D_Clip();
	panel.setPreferredSize(new Dimension(600, 500));
	JFrame frame = new JFrame("Clip a General Path");
	frame.setContentPane(panel);
	frame.pack();
	frame.setVisible(true);		
}
 
Example 10
Source File: AttributeCellEditorToAttributeEditor.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object setValue(Object value) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setPreferredSize(new Dimension(300, 50));
    panel1.removeAll();
    panel.add(editor.getTableCellEditorComponent(null, value, false, 0, 0),
            BorderLayout.NORTH);
    panel1.add(panel);
    panel1.revalidate();
    panel1.repaint();
    return value;
}
 
Example 11
Source File: CheckClipCircle2D.java    From javaGeom with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final static void main(String[] args){
	System.out.println("should draw a circle");
	
	JPanel panel = new CheckClipCircle2D();
	panel.setPreferredSize(new Dimension(400, 400));
	JFrame frame = new JFrame("Check Clip Circle2D");
	frame.setContentPane(panel);
	frame.pack();
	frame.setVisible(true);
	
}
 
Example 12
Source File: RankingGraph.java    From moa with GNU General Public License v3.0 4 votes vote down vote up
private void initComponents() {
    Container container = getContentPane();
    width = getSize().width - 10;
    height = 70 * getSize().height / 100;
    graphPanel = new Graph();
    zoomPanel = new SliderPanel();
    controlPanel = new JPanel();
    imgOptionsPanel = new JPanel();
    exportPanel = new JPanel();
    btnSave = new JButton("Save");
    btnLineStroke = new JButton("Line 1 Stroke");
    btnFont = new JButton("Text Font");
    btnLineDifStronke = new JButton("Line 2 Stroke");
    btnDir = new JButton("Save as");
  
    graphPanelDisplay.setLayout(new BorderLayout());
    graphPanelDisplay.add(graphPanel, BorderLayout.CENTER);
    TitledBorder titleborder;
    titleborder = BorderFactory.createTitledBorder(" Zoom");
    zoomPanel.setBorder(titleborder);
    //titleborder = BorderFactory.createTitledBorder("Options");
    //controlPanel.setBorder(titleborder);
    
    titleborder = BorderFactory.createTitledBorder("Properties");
    imgOptionsPanel.setBorder(titleborder);
    
    titleborder = BorderFactory.createTitledBorder("Export");
    exportPanel.setBorder(titleborder);
    
    graphPanelDisplay.setPreferredSize(new Dimension(width, height));
    controlPanel.setPreferredSize(new Dimension(60 * width / 100,
            20 * getSize().height / 100));
    zoomPanel.setPreferredSize(new Dimension(30 * width / 100,
            20 * getSize().height / 100));
    
    EventControl evt = new EventControl();
    btnFont.addActionListener(evt);
    btnLineDifStronke.addActionListener(evt);
    btnLineStroke.addActionListener(evt);
    btnSave.addActionListener(evt);
    btnDir.addActionListener(evt);
    imgOptionsPanel.add(btnFont);
    imgOptionsPanel.add(btnLineStroke);
    imgOptionsPanel.add(btnLineDifStronke);
    
    exportPanel.setLayout(new BorderLayout());
    JPanel panel = new JPanel();
    //panel.add(new JLabel("Export as "));
   // panel.add(imgType);
   // panel.add(btnSave);
    
    JPanel panelName = new JPanel();
    //panelName.add(new JLabel("File name "));
   // panelName.add(JtextFieldimgName);
    panelName.add(btnDir);
    exportPanel.add(panelName, BorderLayout.CENTER);
    exportPanel.add(panel, BorderLayout.SOUTH);
    
    controlPanel.setLayout(new BorderLayout());
    controlPanel.add(imgOptionsPanel, BorderLayout.CENTER);
    controlPanel.add(exportPanel, BorderLayout.EAST);
    controlPanelDisplay.setLayout(new BorderLayout(1, 1));
    controlPanelDisplay.add(controlPanel, BorderLayout.CENTER);
    controlPanelDisplay.add(zoomPanel, BorderLayout.EAST);
    container.setLayout(new BorderLayout(1, 1));
    container.add("Center", graphPanelDisplay);
    container.add("South", controlPanelDisplay);
    xScale = 20;
    yScale = 20;
    x0 = width / 2;
    y0 = height / 5;
    this.availableStrokeSamples = new StrokeSample[4];
    this.availableStrokeSamples[0] = new StrokeSample(new BasicStroke(1.5f,
            BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER,
            10.0f, dash1, 0.0f));
    this.availableStrokeSamples[1] = new StrokeSample(
            new BasicStroke(1.0f));
    this.availableStrokeSamples[2] = new StrokeSample(
            new BasicStroke(2.0f));
    this.availableStrokeSamples[3] = new StrokeSample(
            new BasicStroke(3.0f));
    
    addWindowStateListener((WindowEvent arg0) -> {
        width = getSize().width - 10;
        height = 70 * getSize().height / 100;
        x0 = width / 2;
        y0 = height / 5;
        xScale = 20;
        yScale = 20;
        xSlider.setValue(50);
        ySlider.setValue(20);
    });
    
}
 
Example 13
Source File: HClusterDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	image = new MBFImage(width, height - 50, ColourSpace.RGB);
	renderer = image.createRenderer(RenderHints.ANTI_ALIASED);
	resetImage();

	ic = new DisplayUtilities.ImageComponent(true, false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	ic.addMouseListener(this);
	ic.addMouseMotionListener(this);
	base.add(ic);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	clearBtn = new JButton("Clear");
	clearBtn.setActionCommand("button.clear");
	clearBtn.addActionListener(this);
	controls.add(clearBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("Distance:"));

	distCombo = new JComboBox<String>();
	distCombo.addItem("Euclidean");
	distCombo.addItem("Manhatten");
	distCombo.addItem("Cosine Distance");
	controls.add(distCombo);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("Linkage:"));

	linkCombo = new JComboBox<String>();
	for (final Linkage s : Linkage.values())
		linkCombo.addItem(s.name());
	controls.add(linkCombo);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run HAC");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	updateImage();

	return base;
}
 
Example 14
Source File: HelpPlayerDialog.java    From dualsub with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void initComponents() {
	// Features
	final int marginLeft = 23;
	this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	this.setResizable(false);
	getContentPane().setLayout(new BorderLayout());
	JPanel panel = new JPanel();
	panel.setLayout(null);
	panel.setPreferredSize(new Dimension(getWidth(), getHeight() + 140));
	panel.setBackground(parent.getBackground());
	JScrollPane scroll = new JScrollPane(panel,
			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
			JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	getContentPane().add(scroll);

	// Title
	final String title = I18N.getHtmlText("PanelOutput.border.text");
	setTitle(I18N.getText("Window.name.text"));
	JLabel lblTitle = new JLabel(title);
	lblTitle.setFont(new Font("Lucida", Font.BOLD, 20));
	lblTitle.setBounds(marginLeft, 21, 435, 25);
	panel.add(lblTitle);

	// Content
	JLabel lblContent01 = new JLabel(
			I18N.getHtmlText("HelpPlayerDialog.help.01"));
	lblContent01.setBounds(marginLeft, 50, 435, 120);
	panel.add(lblContent01);

	JButton lblContent02 = new UrlButton(I18N.getHtmlText(
			"HelpPlayerDialog.help.02", Html.LINK), parent.getCursor(),
			parent.getBackground(), new Rectangle(marginLeft + 20, 170,
					240, 20));
	panel.add(lblContent02);

	UrlButton lblContent03 = new UrlButton(I18N.getHtmlText(
			"HelpPlayerDialog.help.03", Html.LINK), parent.getCursor(),
			parent.getBackground(), new Rectangle(marginLeft + 20, 190,
					240, 20));
	panel.add(lblContent03);

	UrlButton lblContent04 = new UrlButton(I18N.getHtmlText(
			"HelpPlayerDialog.help.04", Html.LINK), parent.getCursor(),
			parent.getBackground(), new Rectangle(marginLeft + 20, 210,
					240, 20));
	panel.add(lblContent04);

	JLabel lblContent05 = new JLabel(
			I18N.getHtmlText("HelpPlayerDialog.help.05"));
	lblContent05.setBounds(marginLeft, 230, 435, 180);
	panel.add(lblContent05);

	JLabel lblContent06 = new JLabel(
			I18N.getHtmlText("HelpPlayerDialog.help.06"));
	lblContent06.setBounds(marginLeft, 410, 435, 100);
	panel.add(lblContent06);

	JLabel lblContent07 = new JLabel(
			I18N.getHtmlText("HelpPlayerDialog.help.07"));
	lblContent07.setBounds(marginLeft + 20, 510, 415, 40);
	panel.add(lblContent07);

	// Borders (for debug purposes)
	if (log.isTraceEnabled()) {
		Border border = BorderFactory.createLineBorder(Color.black);
		lblTitle.setBorder(border);
		lblContent01.setBorder(border);
		lblContent02.setBorderPainted(true);
		lblContent02.setBorder(border);
		lblContent03.setBorder(border);
		lblContent03.setBorderPainted(true);
		lblContent04.setBorder(border);
		lblContent04.setBorderPainted(true);
		lblContent05.setBorder(border);
		lblContent06.setBorder(border);
		lblContent07.setBorder(border);
		panel.setBorder(border);
	}
}
 
Example 15
Source File: ViewMapping.java    From AML-Project with Apache License 2.0 4 votes vote down vote up
private void buildDetailPanel()
{
	//Setup the panels
	details = new JPanel();
	details.setLayout(new BoxLayout(details, BoxLayout.Y_AXIS));
	JPanel topFiller = new JPanel();
	topFiller.setPreferredSize(new Dimension(topFiller.getPreferredSize().width,10));
	topFiller.setMaximumSize(new Dimension(topFiller.getMaximumSize().width,10));
	details.add(topFiller);
	
	if(t.equals(EntityType.CLASS))
	{
		sourcePanel = buildClassDetailPanel(sourceId);
		sourcePanel.setBorder(new TitledBorder("Source Class:"));
		targetPanel = buildClassDetailPanel(targetId);
		targetPanel.setBorder(new TitledBorder("Target Class:"));
	}
	else if(t.equals(EntityType.INDIVIDUAL))
	{
		sourcePanel = buildIndivDetailPanel(sourceId);
		sourcePanel.setBorder(new TitledBorder("Source Individual:"));
		targetPanel = buildIndivDetailPanel(targetId);
		targetPanel.setBorder(new TitledBorder("Target Individual:"));
	}
	else
	{
		sourcePanel = buildPropDetailPanel(sourceId);
		sourcePanel.setBorder(new TitledBorder("Source Property:"));
		targetPanel = buildPropDetailPanel(targetId);
		targetPanel.setBorder(new TitledBorder("Target Property:"));
	}
	
	//Set the sizes of the subpanels and add them to the details panel
	sourcePanel.setPreferredSize(new Dimension((int)(width*0.85),sourcePanel.getPreferredSize().height));
	sourcePanel.setMaximumSize(new Dimension((int)(width*0.85),sourcePanel.getPreferredSize().height));
	details.add(sourcePanel);
	JPanel midFiller1 = new JPanel();
	midFiller1.setPreferredSize(new Dimension(midFiller1.getPreferredSize().width,10));
	midFiller1.setMaximumSize(new Dimension(midFiller1.getMaximumSize().width,10));
	details.add(midFiller1);
	targetPanel.setPreferredSize(new Dimension((int)(width*0.85),targetPanel.getPreferredSize().height));
	targetPanel.setMaximumSize(new Dimension((int)(width*0.85),targetPanel.getPreferredSize().height));
	details.add(targetPanel);
	JPanel midFiller2 = new JPanel();
	midFiller2.setPreferredSize(new Dimension(midFiller2.getPreferredSize().width,10));
	midFiller2.setMaximumSize(new Dimension(midFiller2.getMaximumSize().width,10));
	details.add(midFiller2);
	//Initialize and construct the mapping panel
	JPanel mappingPanel = new JPanel();
	mappingPanel.setLayout(new BoxLayout(mappingPanel, BoxLayout.Y_AXIS));
	mappingPanel.setBorder(new TitledBorder("Mapping:"));
       JLabel type = new JLabel("<html>Type: <i>" + t + " Mapping</i></html>");
	mappingPanel.add(type);
       JLabel sim = new JLabel("<html>Final Similarity: <i>" + m.getSimilarityPercent() + "</i></html>");
       mappingPanel.add(sim);
       if(t.equals(EntityType.CLASS))
       {
        QualityFlagger qf = aml.getQualityFlagger();
        if(qf != null)
        {
        	Vector<String> labels = qf.getLabels();
        	for(int i = 0; i < labels.size(); i++)
        	{
        		JLabel simQ = new JLabel("<html>" + labels.get(i) + "<i>" +
        				qf.getSimilarityPercent(sourceId,targetId,i) + "</i></html>");
        		mappingPanel.add(simQ);
        	}
        }
       }
	//Set its size and add it to the details panel
	mappingPanel.setPreferredSize(new Dimension((int)(width*0.85),mappingPanel.getPreferredSize().height));
	mappingPanel.setMaximumSize(new Dimension((int)(width*0.85),mappingPanel.getPreferredSize().height));
	details.add(mappingPanel);
	JPanel bottomFiller = new JPanel();
	details.add(bottomFiller);
}
 
Example 16
Source File: ViewOptions.java    From AML-Project with Apache License 2.0 4 votes vote down vote up
public ViewOptions()
{
	super();
	aml = AML.getInstance();
	
	this.setTitle("Graph Options");
	this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
	
	languageLabel = new JLabel("Label Language:");
	Vector<String> languages = new Vector<String>(aml.getLanguages());
	languageSelector = new JComboBox<String>(languages);
	languageSelector.setSelectedItem(aml.getLabelLanguage());
	languagePanel = new JPanel();
	languagePanel.add(languageLabel);
	languagePanel.add(languageSelector);

	ancestors = new JCheckBox("View Ancestors");
	ancestors.setMnemonic(KeyEvent.VK_C);
	ancestors.setSelected(AML.getInstance().showAncestors());
	descendants = new JCheckBox("View Descendants");
	descendants.setMnemonic(KeyEvent.VK_C);
	descendants.setSelected(AML.getInstance().showDescendants());
	directionPanel = new JPanel();
	directionPanel.add(ancestors);
	directionPanel.add(descendants);
	
	classLabel = new JLabel("Class extension (edges):");
	classSelector = new JComboBox<Integer>(DIST);
	classSelector.setSelectedIndex(AML.getInstance().getClassDistance());
       classPanel = new JPanel();
	classPanel.add(classLabel);
	classPanel.add(classSelector);
	
	individualLabel = new JLabel("Individual extension (edges):");
	individualSelector = new JComboBox<Integer>(DIST);
	individualSelector.setSelectedIndex(AML.getInstance().getIndividualDistance());
	individualPanel = new JPanel();
	individualPanel.add(individualLabel);
	individualPanel.add(individualSelector);

	cancel = new JButton("Cancel");
	cancel.setPreferredSize(new Dimension(70,28));
	cancel.addActionListener(this);
	ok = new JButton("OK");
	ok.setPreferredSize(new Dimension(70,28));
	ok.addActionListener(this);
	buttonPanel = new JPanel();
	buttonPanel.add(cancel);
	buttonPanel.add(ok);
	
	dialogPanel = new JPanel();
	dialogPanel.setPreferredSize(new Dimension(300,150));
	dialogPanel.setLayout(new BoxLayout(dialogPanel, BoxLayout.PAGE_AXIS));
	if(!aml.getLanguageSetting().equals(LanguageSetting.SINGLE))
		dialogPanel.add(languagePanel);
	dialogPanel.add(directionPanel);
	dialogPanel.add(classPanel);
	dialogPanel.add(individualPanel);
	dialogPanel.add(buttonPanel);
	
	add(dialogPanel);
       
       this.pack();
	GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
	int left = g.getCenterPoint().x - (int)(this.getPreferredSize().width / 2);
	this.setLocation(left, 0);
       this.setVisible(true);
}
 
Example 17
Source File: BasicTextField.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void main(String... args) {
	final int x = 50;
	final int y = 50;
	JFrame f = new JFrame();

	final BasicTextField tf1 = new BasicTextField();
	tf1.setText("111");
	tf1.setPosition(x,  y);
	tf1.setJustification(JUSTIFY_RIGHT, JUSTIFY_BOTTOM);

	final BasicTextField tf2 = new BasicTextField();
	tf2.setText("222");
	tf2.setPosition(x,  y);
	tf2.setJustification(JUSTIFY_LEFT, JUSTIFY_BOTTOM);

	final BasicTextField tf3 = new BasicTextField();
	tf3.setText("333");
	tf3.setPosition(x,  y);
	tf3.setJustification(JUSTIFY_RIGHT, JUSTIFY_TOP);

	final BasicTextField tf4 = new BasicTextField();
	tf4.setText("444");
	tf4.setPosition(x,  y);
	tf4.setJustification(JUSTIFY_LEFT, JUSTIFY_TOP);
	JPanel p = new JPanel() {
		private static final long serialVersionUID = 1420261164629448825L;

		@Override
		public void paintComponent(Graphics g) {
			g.drawLine(0, y, getWidth(), y);
			g.drawLine(x, 0, x, getHeight());
			tf1.paint(g);
			tf2.paint(g);
			tf3.paint(g);
			tf4.paint(g);
		}
	};
	p.addMouseListener(tf1);
	p.addMouseListener(tf2);
	p.addMouseListener(tf3);
	p.addMouseListener(tf4);
	p.addKeyListener(tf1);
	p.addKeyListener(tf2);
	p.addKeyListener(tf3);
	p.addKeyListener(tf4);
	p.setPreferredSize(new Dimension(300, 300));
	f.getContentPane().add(p);
	f.pack();
	f.setVisible(true);
}
 
Example 18
Source File: MouseOptions.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
public MouseOptions(OptionsFrame window) {
	super(window, new GridLayout(1, 3));

	explorer = new ProjectExplorer(getProject());
	explorer.setListener(listener);

	// Area for adding mappings
	addArea.addMouseListener(listener);

	// Area for viewing current mappings
	model = new MappingsModel();
	mappings.setTableHeader(null);
	mappings.setModel(model);
	mappings.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	mappings.getSelectionModel().addListSelectionListener(listener);
	mappings.clearSelection();
	JScrollPane mapPane = new JScrollPane(mappings);

	// Button for removing current mapping
	JPanel removeArea = new JPanel();
	remove.addActionListener(listener);
	remove.setEnabled(false);
	removeArea.add(remove);

	// Area for viewing/changing attributes
	attrTable = new AttrTable(getOptionsFrame());

	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints gbc = new GridBagConstraints();
	setLayout(gridbag);
	gbc.weightx = 1.0;
	gbc.weighty = 1.0;
	gbc.gridheight = 4;
	gbc.fill = GridBagConstraints.BOTH;
	JScrollPane explorerPane = new JScrollPane(explorer, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	gridbag.setConstraints(explorerPane, gbc);
	add(explorerPane);
	gbc.weightx = 0.0;
	JPanel gap = new JPanel();
	gap.setPreferredSize(new Dimension(10, 10));
	gridbag.setConstraints(gap, gbc);
	add(gap);
	gbc.weightx = 1.0;
	gbc.gridheight = 1;
	gbc.gridx = 2;
	gbc.gridy = GridBagConstraints.RELATIVE;
	gbc.weighty = 0.0;
	gridbag.setConstraints(addArea, gbc);
	add(addArea);
	gbc.weighty = 1.0;
	gridbag.setConstraints(mapPane, gbc);
	add(mapPane);
	gbc.weighty = 0.0;
	gridbag.setConstraints(removeArea, gbc);
	add(removeArea);
	gbc.weighty = 1.0;
	gridbag.setConstraints(attrTable, gbc);
	add(attrTable);

	getOptions().getMouseMappings().addMouseMappingsListener(listener);
	setCurrentTool(null);
}
 
Example 19
Source File: AbstractAdapterEditor.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
void addComboField(JPanel parent, String labelText, String propertyName, List<String> values) {
    JLabel jLabel = new JLabel(labelText);
    parent.add(jLabel);

    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(propertyName);
    propertyDescriptor.setNotEmpty(true);

    values.sort(Comparator.naturalOrder());

    propertyDescriptor.setValueSet(new ValueSet(values.toArray()));
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComp = editor.createEditorComponent(propertyDescriptor, bindingContext);
    if (editorComp instanceof JComboBox) {
        JComboBox comboBox = (JComboBox)editorComp;
        comboBox.setEditable(true);
    }
    editorComp.setMaximumSize(new Dimension(editorComp.getMaximumSize().width, controlHeight));

    customMenuLocation = new JTextField();
    customMenuLocation.setInputVerifier(new RequiredFieldValidator(Bundle.MSG_Empty_MenuLocation_Text()));
    customMenuLocation.setEnabled(false);

    JPanel subPanel = new JPanel(new SpringLayout());
    subPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    JRadioButton rbExistingMenu = new JRadioButton(Bundle.CTL_Label_RadioButton_ExistingMenus(), true);
    rbMenuNew = new JRadioButton(Bundle.CTL_Label_RadioButton_NewMenu());
    ButtonGroup rbGroup = new ButtonGroup();
    rbGroup.add(rbExistingMenu);
    rbGroup.add(rbMenuNew);
    // this radio button should be able to capture focus even when the validator of the rbMenuNew says otherwise
    rbExistingMenu.setVerifyInputWhenFocusTarget(false);
    rbExistingMenu.addItemListener(e -> {
        editorComp.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
        customMenuLocation.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
    });
    subPanel.add(rbExistingMenu);
    subPanel.add(rbMenuNew);
    jLabel.setLabelFor(editorComp);
    subPanel.add(editorComp);
    subPanel.add(customMenuLocation);

    Dimension dimension = new Dimension(parent.getWidth() / 2, controlHeight);
    editorComp.setPreferredSize(dimension);
    customMenuLocation.setPreferredSize(dimension);

    subPanel.setPreferredSize(new Dimension(subPanel.getWidth(), (int)(2.5 * controlHeight)));
    subPanel.setMaximumSize(new Dimension(subPanel.getWidth(), (int) (2.5 * controlHeight)));

    makeCompactGrid(subPanel, 2, 2, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    parent.add(subPanel);
}
 
Example 20
Source File: TemplateParameterEditorDialog.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void addComponents() {
    Property property = getProperty();
    try {
        Template template = this.modifiedParameter.getTemplate();
        property.setValue(template.getPath());
    } catch (ValidationException e) {
        logger.warning(e.getMessage());
    }

    FileEditor fileEditor = new FileEditor();
    JComponent filePathComponent = fileEditor.createEditorComponent(property.getDescriptor(), this.paramContext);
    filePathComponent.setPreferredSize(new Dimension(770, 25));

    JPanel topPanel = new JPanel(new BorderLayout());
    JPanel filePanel = new JPanel();
    final JLabel label = new JLabel("File:");
    filePanel.add(label);
    filePanel.add(filePathComponent);
    topPanel.add(filePanel, BorderLayout.NORTH);

    JPanel outFilePanel = new JPanel();
    final JLabel jLabel = new JLabel("Output File:");
    outFilePanel.add(jLabel);
    File outputFile = this.modifiedParameter.getOutputFile();
    outFileName = new JTextField(outputFile != null ? outputFile.toString() : "");
    outFileName.setPreferredSize(
            new Dimension(filePathComponent.getPreferredSize().width + label.getPreferredSize().width - jLabel.getPreferredSize().width, 25));
    org.esa.snap.utils.UIUtils.addPromptSupport(outFileName, "Enter the name of transformed file here");
    outFilePanel.add(outFileName);
    topPanel.add(outFilePanel, BorderLayout.WEST);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setPreferredSize(new Dimension(800, 550));
    mainPanel.add(topPanel, BorderLayout.PAGE_START);

    //to create UI component for outputFile
    fileContentArea.setAutoCompleteEntries(getAutocompleteEntries());
    fileContentArea.setTriggerChar('$');
    mainPanel.add(new JScrollPane(fileContentArea), BorderLayout.CENTER);

    updateFileAreaContent();

    mainPanel.add(createParametersPanel(), BorderLayout.PAGE_END);

    setContent(mainPanel);
}