Java Code Examples for javax.swing.JLabel.setHorizontalTextPosition()

The following are Jave code examples for showing how to use setHorizontalTextPosition() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table, 
                                               Object value,
                                               boolean isSelected, 
                                               boolean hasFocus,
                                               int row, 
                                               int column) {
    Component c = tableCellRenderer.getTableCellRendererComponent(table, 
            value, isSelected, hasFocus, row, column);
    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;
        int modelColumn = table.convertColumnIndexToModel(column);
        Directive directive = getDirective(modelColumn);
        if (directive != EMPTY_DIRECTIVE) {
            l.setFont(l.getFont().deriveFont(Font.BOLD));
        }
        l.setHorizontalTextPosition(JLabel.LEFT);
        l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
    }
    return c;
}
 
Example 2
Project: incubator-netbeans   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
    Component c = tableCellRenderer.getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;
        l.setHorizontalTextPosition(JLabel.LEFT);
        int modelColumn = table.convertColumnIndexToModel(column);
        l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
    }
    return c;
}
 
Example 3
Project: incubator-netbeans   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {
    Component c = tableCellRenderer.getTableCellRendererComponent(table,
            value, isSelected, hasFocus, row, column);
    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;
        l.setHorizontalTextPosition(JLabel.LEFT);
        int modelColumn = table.convertColumnIndexToModel(column);
        l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
    }
    return c;
}
 
Example 4
Project: dev-courses   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus, int row,
        int column) {

    Component c =
        tableCellRenderer.getTableCellRendererComponent(table, value,
            isSelected, hasFocus, row, column);

    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;

        l.setHorizontalTextPosition(JLabel.LEFT);

        int modelColumn = table.convertColumnIndexToModel(column);

        l.setIcon(getHeaderRendererIcon(modelColumn,
                                        l.getFont().getSize()));
    }

    return c;
}
 
Example 5
Project: OpenDiabetes   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus, int row,
        int column) {

    Component c =
        tableCellRenderer.getTableCellRendererComponent(table, value,
            isSelected, hasFocus, row, column);

    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;

        l.setHorizontalTextPosition(JLabel.LEFT);

        int modelColumn = table.convertColumnIndexToModel(column);

        l.setIcon(getHeaderRendererIcon(modelColumn,
                                        l.getFont().getSize()));
    }

    return c;
}
 
Example 6
Project: GIFKR   File: ProgressFrame.java   Source Code and License Vote up 6 votes
private void initializeComponents() {
	progressText = new JLabel(new ImageIcon(ImageTools.scaleToHeight(ImageTools.getResourceImage("iconsmall.png"), 50, false)));
	progressText.setForeground(Color.white);
	progressText.setVerticalTextPosition(JLabel.BOTTOM);
	progressText.setHorizontalTextPosition(JLabel.CENTER);
	cancelButton = new JButton("Cancel");
	
	setContentPane(new JPanel() {
		private static final long serialVersionUID = -8098561857624764691L;
		@Override
		public void paintComponent(Graphics g) {
			setOpaque(false);
			super.paintComponent(g);
			paintBG((Graphics2D) g);
		}
	});
	cancelButton.addActionListener(ae -> {if(onCancel != null) onCancel.actionPerformed(ae);});
}
 
Example 7
Project: LivroJavaComoProgramar10Edicao   File: LabelFrame.java   Source Code and License Vote up 6 votes
public LabelFrame()
{
   super("Testing JLabel");
   setLayout(new FlowLayout()); // set frame layout

   // JLabel constructor with a string argument
   label1 = new JLabel("Label with text");
   label1.setToolTipText("This is label1");
   add(label1); // add label1 to JFrame

   // JLabel constructor with string, Icon and alignment arguments
   Icon bug = new ImageIcon(getClass().getResource("bug1.png"));
   label2 = new JLabel("Label with text and icon", bug, 
      SwingConstants.LEFT);
   label2.setToolTipText("This is label2");
   add(label2); // add label2 to JFrame

   label3 = new JLabel(); // JLabel constructor no arguments
   label3.setText("Label with icon and text at bottom");
   label3.setIcon(bug); // add icon to JLabel
   label3.setHorizontalTextPosition(SwingConstants.CENTER);
   label3.setVerticalTextPosition(SwingConstants.BOTTOM);
   label3.setToolTipText("This is label3");
   add(label3); // add label3 to JFrame
}
 
Example 8
Project: parabuild-ci   File: TableSorter.java   Source Code and License Vote up 6 votes
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus, int row,
        int column) {

    Component c =
        tableCellRenderer.getTableCellRendererComponent(table, value,
            isSelected, hasFocus, row, column);

    if (c instanceof JLabel) {
        JLabel l = (JLabel) c;

        l.setHorizontalTextPosition(JLabel.LEFT);

        int modelColumn = table.convertColumnIndexToModel(column);

        l.setIcon(getHeaderRendererIcon(modelColumn,
                                        l.getFont().getSize()));
    }

    return c;
}
 
Example 9
Project: Equella   File: AbstractListWithView.java   Source Code and License Vote up 5 votes
protected Component getNoSelectionComponent()
{
	JLabel label = new JLabel(getNoSelectionText());

	// Centre it!
	label.setVerticalAlignment(SwingConstants.CENTER);
	label.setHorizontalAlignment(SwingConstants.CENTER);
	label.setVerticalTextPosition(SwingConstants.CENTER);
	label.setHorizontalTextPosition(SwingConstants.CENTER);

	return label;
}
 
Example 10
Project: jmt   File: AboutDialogPanel.java   Source Code and License Vote up 5 votes
/**
 * Initialize the panel
 */
private void initialize() {
	// Initialize dialog layout
	
	JPanel panel = new JPanel(new BorderLayout(BORDERSIZE / 2, BORDERSIZE / 2));
	panel.setBorder(BorderFactory.createEmptyBorder(BORDERSIZE, BORDERSIZE, BORDERSIZE, BORDERSIZE));
	// Adds website image
	JPanel tmpPanel = new JPanel(new BorderLayout(BORDERSIZE, BORDERSIZE));
	// Adds polimi description
	HtmlPanel titleLabel = new HtmlPanel();
	titleLabel.setText(GraphStartScreen.HTML_CONTENT_TITLE_HREF);
	titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	titleLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
	titleLabel.setOpaque(false);
	tmpPanel.add(titleLabel, BorderLayout.CENTER);

	// Adds application title
	title = new JLabel();
	title.setHorizontalTextPosition(SwingConstants.RIGHT);
	title.setHorizontalAlignment(SwingConstants.CENTER);
	title.setIconTextGap(BORDERSIZE);
	tmpPanel.add(title, BorderLayout.SOUTH);

	panel.add(tmpPanel, BorderLayout.NORTH);

	// Adds text area
	mainArea = new JPanel();
	mainArea.setOpaque(false);
	BoxLayout mainLayout = new BoxLayout(mainArea, BoxLayout.Y_AXIS);
	mainArea.setLayout(mainLayout);
	
	panel.add(mainArea, BorderLayout.CENTER);

	JLabel legal = new JLabel(LEGAL);
	panel.add(legal, BorderLayout.SOUTH);
	panel.setPreferredSize(new Dimension(600,480));
	JScrollPane scroll = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	this.add(scroll, BorderLayout.CENTER);
}
 
Example 11
Project: jmt   File: WarningWindow.java   Source Code and License Vote up 5 votes
/**
 * This is used to create components to be shown inside box
 * @param text text to be displayed inside box
 * @return created component
 */
private Component getEntry(String text) {
	JLabel label = new JLabel("<HTML>" + text + "</HTML>");
	label.setIcon(JMTImageLoader.loadImage("Warning"));
	label.setIconTextGap(BORDER);
	label.setHorizontalTextPosition(SwingConstants.RIGHT);
	label.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
	return label;
}
 
Example 12
Project: jmt   File: TestWizardPanel.java   Source Code and License Vote up 5 votes
public TestWizardPanel() {
	counter++;
	name = "Panel " + counter;
	JLabel jl = new JLabel("<html><center>This is <b>" + name + "</b>.<br>Have a nice day!</center></html>");
	jl.setHorizontalAlignment(SwingConstants.CENTER);
	jl.setHorizontalTextPosition(SwingConstants.CENTER);
	jl.setFont(new Font("Arial", Font.PLAIN, 16));
	jl.setBorder(BorderFactory.createEtchedBorder());

	setLayout(new BorderLayout());

	add(jl, BorderLayout.CENTER);
}
 
Example 13
Project: Progetto-B   File: GUI.java   Source Code and License Vote up 5 votes
/**
 * Updates the JLabel that belongs to <code>countryInfo</code> with the new
 * number of armies on that country.
 *
 * @param countryInfo
 */
@Override
public void updateOnArmiesChange(CountryInfo countryInfo) {

    JLabel label = countryLabelMap.get(countryInfo.getName());
    label.setForeground(Color.WHITE);
    label.setText(Integer.toString(countryInfo.getArmies()));
    label.setHorizontalTextPosition(JLabel.CENTER);
    label.setIcon(new ImageIcon("src/resources/images/labelCountry/" + countryInfo.getPlayerColor() + "label1.png"));

    repaint(label);
}
 
Example 14
Project: QN-ACTR-Release   File: WarningWindow.java   Source Code and License Vote up 5 votes
/**
 * This is used to create components to be shown inside box
 * @param text text to be displayed inside box
 * @return created component
 */
private Component getEntry(String text) {
	JLabel label = new JLabel("<HTML>" + text + "</HTML>");
	label.setIcon(JMTImageLoader.loadImage("Warning"));
	label.setIconTextGap(BORDER);
	label.setHorizontalTextPosition(SwingConstants.RIGHT);
	label.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
	return label;
}
 
Example 15
Project: Neukoelln_SER316   File: JNCalendarCellRenderer.java   Source Code and License Vote up 4 votes
public Component getTableCellRendererComponent(
      JTable table,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      int row,
      int column) {
      
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String currentPanel = ((AppFrame)App.getFrame()).workPanel.dailyItemsPanel.getCurrentPanel();

if (d == null) {
          label.setEnabled(false);
	label.setIcon(null);
          label.setBackground(new Color(212, 246, 246));
          return label;
      }
      
if (!isSelected) {
	CalendarDate cpsd = CurrentProject.get().getStartDate();
          CalendarDate cped = CurrentProject.get().getEndDate();
          if (!(((d.after(cpsd)) && (d.before(cped))) || (d.equals(cpsd)) || (d.equals(cped)))) {
		label.setBackground(new Color(212, 246, 246));
		return label;
	}
      }		


label.setHorizontalTextPosition(2);
label.setEnabled(true);



      if (d.equals(CalendarDate.today())) {
          label.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 128)));
      }
      
// set foreground color
if (d.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
          label.setForeground(new Color(255, 0, 0));
      }
else { 		
	label.setForeground(Color.BLACK);
}

// set background color
if (currentPanel == null)
	label.setBackground(Color.WHITE);

else if (currentPanel.equals("TASKS") && (t != null) && 
	(d.inPeriod(t.getStartDate(), t.getEndDate()))) 
		label.setBackground(new Color(212, 246, 246));

else if(currentPanel.equals("NOTES") && 
CurrentProject.getNoteList().getNoteForDate(d) != null) 
			label.setBackground(new Color(212, 246, 246));

else if(currentPanel.equals("EVENTS") && 
(!(EventsManager.getEventsForDate(d).isEmpty()))) 
			label.setBackground(new Color(212, 246, 246));

else if(!isSelected)
	label.setBackground(Color.WHITE);
		
// always display NREvents
if (EventsManager.isNREventsForDate(d))
	label.setIcon(evIcon);
else
	label.setIcon(null);

      return label;
  }
 
Example 16
Project: Dahlem_SER316   File: JNCalendarCellRenderer.java   Source Code and License Vote up 4 votes
public Component getTableCellRendererComponent(
      JTable table,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      int row,
      int column) {
      
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String currentPanel = ((AppFrame)App.getFrame()).workPanel.dailyItemsPanel.getCurrentPanel();

if (d == null) {
          label.setEnabled(false);
	label.setIcon(null);
          label.setBackground(ColorPanels.highlightColor1);
          return label;
      }
      
if (!isSelected) {
	CalendarDate cpsd = CurrentProject.get().getStartDate();
          CalendarDate cped = CurrentProject.get().getEndDate();
          if (!(((d.after(cpsd)) && (d.before(cped))) || (d.equals(cpsd)) || (d.equals(cped)))) {
          	label.setBackground(ColorPanels.highlightColor1);
		return label;
	}
      }		


label.setHorizontalTextPosition(2);
label.setEnabled(true);



      if (d.equals(CalendarDate.today())) {
          label.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 128)));
      }
      
// set foreground color
if (d.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
          label.setForeground(new Color(255, 0, 0));
      }
else { 		
	label.setForeground(Color.BLACK);
}

// set background color
if (currentPanel == null)
	label.setBackground(ColorPanels.highlightColor1);

else if (currentPanel.equals("TASKS") && (t != null) && 
	(d.inPeriod(t.getStartDate(), t.getEndDate()))) 
		label.setBackground( new Color(230, 255, 230));

else if(currentPanel.equals("NOTES") && 
CurrentProject.getNoteList().getNoteForDate(d) != null) 
			label.setBackground(new Color(255,245,200));

else if(currentPanel.equals("EVENTS") && 
(!(EventsManager.getEventsForDate(d).isEmpty()))) 
			label.setBackground(new Color(255,230,230));

else if(!isSelected)
	label.setBackground(ColorPanels.highlightColor1);
		
// always display NREvents
if (EventsManager.isNREventsForDate(d))
	label.setIcon(evIcon);
else
	label.setIcon(null);

      return label;
  }
 
Example 17
Project: Equella   File: GlassProgressPane.java   Source Code and License Vote up 4 votes
protected GlassProgressPane(final String messageText, final int total, final Component activeComponent,
	final boolean stopClosing, final AdvancedSwingWorker<?> worker, final boolean cancellable)
{
	super(activeComponent, stopClosing);

	this.worker = worker;

	message = new JLabel(messageText);
	message.setForeground(Color.WHITE);
	message.setHorizontalAlignment(SwingConstants.CENTER);
	message.setHorizontalTextPosition(SwingConstants.CENTER);

	Font font = message.getFont();
	message.setFont(new Font(font.getFamily(), Font.BOLD, (int) (font.getSize() * 1.2)));

	progress = new JProgressBar();
	setTotal(total);

	// We cannot I18N the button text, as this class is initialised before
	// CurrentLocale.
	cancel = new JButton("Cancel");
	cancel.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			cancel.setEnabled(false);
			GlassProgressPane.this.worker.interrupt();
		}
	});

	final int height1 = message.getPreferredSize().height;
	final int height2 = progress.getPreferredSize().height;
	final int height3 = cancel.getPreferredSize().height;
	final int width1 = cancel.getPreferredSize().width;

	final int[] rows = {height3, TableLayout.FILL, height1, height2, TableLayout.FILL, height3,};
	final int[] cols = {width1, TableLayout.FILL, 100, TableLayout.FILL, width1,};

	setLayout(new TableLayout(rows, cols));
	setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
	add(message, new Rectangle(0, 2, 5, 1));
	add(progress, new Rectangle(2, 3, 1, 1));
	add(cancel, new Rectangle(4, 5, 1, 1));

	setCancellable(cancellable);
}
 
Example 18
Project: gate-core   File: ProgressPanel.java   Source Code and License Vote up 4 votes
public ProgressPanel() {
  super();

  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

  progressTotal = new SafeJProgressBar();
  progressTotal.setAlignmentX(CENTER_ALIGNMENT);
  progressTotal.setMaximumSize(new Dimension(250, progressTotal
          .getPreferredSize().height));
  progressTotal.setIndeterminate(true);

  progressSingle = new SafeJProgressBar();
  progressSingle.setAlignmentX(CENTER_ALIGNMENT);
  progressSingle.setMaximumSize(new Dimension(250, progressTotal
          .getPreferredSize().height));
  progressSingle.setIndeterminate(true);
  progressSingle.setVisible(false);
  progressSingle.setMinimum(0);
  progressSingle.setMaximum(100);

  message = new JLabel("");
  message.setIcon(new ProgressIcon(48, 48));
  message.setHorizontalTextPosition(SwingConstants.RIGHT);
  message.setHorizontalAlignment(SwingConstants.CENTER);
  message.setAlignmentX(CENTER_ALIGNMENT);

  dlMsg = new JLabel("Downloading CREOLE Plugin...");
  dlMsg.setIcon(new DownloadIcon(48, 48));
  dlMsg.setHorizontalTextPosition(SwingConstants.RIGHT);
  dlMsg.setHorizontalAlignment(SwingConstants.CENTER);
  dlMsg.setAlignmentX(CENTER_ALIGNMENT);
  dlMsg.setVisible(false);

  add(Box.createVerticalGlue());
  add(message);
  add(Box.createVerticalStrut(5));
  add(progressTotal);
  add(Box.createVerticalStrut(10));
  add(dlMsg);
  add(Box.createVerticalStrut(5));
  add(progressSingle);
  add(Box.createVerticalGlue());

  addComponentListener(this);
}
 
Example 19
Project: Equella   File: AdminToolList.java   Source Code and License Vote up 4 votes
@Override
public void setup(Set<String> grantedPrivileges, String name)
{
	getButtonActions(actions);

	listFilled = false;
	model = new GenericListModel<NameValue>();

	list = new JList<>(model);
	list.addMouseListener(new ListDoubleClickListener(list, editAction));
	list.addMouseListener(new ListPopupListener(list, actions));
	list.addListSelectionListener(new ListSelectionListener()
	{
		@Override
		public void valueChanged(ListSelectionEvent e)
		{
			updateButtons();
		}
	});

	JScrollPane scroll = new JScrollPane(list);

	JLabel heading = new JLabel(name);
	heading.setHorizontalAlignment(SwingConstants.CENTER);
	heading.setHorizontalTextPosition(SwingConstants.CENTER);

	JButton refreshButton = new JTextlessButton(refreshAction);
	refreshButton.setBorderPainted(false);
	refreshButton.setIconTextGap(0);
	refreshButton.setBorder(null);

	JComponent buttonsComp = createButtonsPanel();

	final int width1 = refreshButton.getPreferredSize().width;
	final int height1 = refreshButton.getPreferredSize().height;
	final int height2 = buttonsComp.getPreferredSize().height;

	final int[] rows = {5, height1, 5, TableLayout.FILL, 5, height2,};
	final int[] cols = {width1, TableLayout.FILL, width1, 5};

	everything = new JPanel(new TableLayout(rows, cols, 0, 0));
	everything.add(heading, new Rectangle(1, 1, 1, 1));
	everything.add(refreshButton, new Rectangle(2, 1, 1, 1));
	everything.add(scroll, new Rectangle(0, 3, 3, 1));
	everything.add(buttonsComp, new Rectangle(0, 5, 3, 1));

	updateButtons();
}
 
Example 20
Project: Wilmersdorf_SER316   File: JNCalendarCellRenderer.java   Source Code and License Vote up 4 votes
public Component getTableCellRendererComponent(
      JTable table,
      Object value,
      boolean isSelected,
      boolean hasFocus,
      int row,
      int column) {
      
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
String currentPanel = ((AppFrame)App.getFrame()).workPanel.dailyItemsPanel.getCurrentPanel();

if (d == null) {
          label.setEnabled(false);
	label.setIcon(null);
          label.setBackground(new Color(0xE0,0xE0,0xE0));
          return label;
      }
      
if (!isSelected) {
	CalendarDate cpsd = CurrentProject.get().getStartDate();
          CalendarDate cped = CurrentProject.get().getEndDate();
          if (!(((d.after(cpsd)) && (d.before(cped))) || (d.equals(cpsd)) || (d.equals(cped)))) {
		label.setBackground(new Color(0xF0,0xF0,0xF0));
		return label;
	}
      }		


label.setHorizontalTextPosition(2);
label.setEnabled(true);



      if (d.equals(CalendarDate.today())) {
          label.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 128)));
      }
      
// set foreground color
if (d.getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
          label.setForeground(new Color(255, 0, 0));
      }
else { 		
	label.setForeground(Color.BLACK);
}

// set background color
if (currentPanel == null)
	label.setBackground(Color.WHITE);

else if (currentPanel.equals("TASKS") && (t != null) && 
	(d.inPeriod(t.getStartDate(), t.getEndDate()))) 
		label.setBackground( new Color(230, 255, 230));

else if(currentPanel.equals("NOTES") && 
CurrentProject.getNoteList().getNoteForDate(d) != null) 
			label.setBackground(new Color(255,245,200));

else if(currentPanel.equals("EVENTS") && 
(!(EventsManager.getEventsForDate(d).isEmpty()))) 
			label.setBackground(new Color(255,230,230));

else if(!isSelected)
	label.setBackground(Color.WHITE);
		
// always display NREvents
if (EventsManager.isNREventsForDate(d))
	label.setIcon(evIcon);
else
	label.setIcon(null);

      return label;
  }