Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Background color and html (Read 2013 times)
Bruno Dufour
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Jul 28th, 2022
Background color and html
Aug 9th, 2022 at 12:44pm
Print Post  
Is there a way to control the background color of a specific appointment ?

See the attach file (png). Can we replace the green by something else for a specific appointment (example: when the appointment must be cancel, I will like to see it in red).

In addition,

From the list view (see picture), We have plenty of space to add text to detail the appointment. can we add html to format the text (is is similar to a JLabel)? And, what is the method to add text in that zone (the green space).



  

Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3410
Joined: Oct 19th, 2005
Re: Background color and html
Reply #1 - Aug 9th, 2022 at 1:40pm
Print Post  
For background, call appointment.getStyle().setBrush(...); in other views you might have to call setHeaderBrush instead.

There's only a limited html subset supported for items' DescriptionText shown in TimeTable view. For full JLabel's HTML rendering in any view, you could try custom drawing:

Code
Select All
app.setHeaderText(
    "<html><i>test</i> <font size='16'><b>test</b></font></html>");

calendar.setCustomDraw(
    EnumSet.of(CustomDrawElements.CalendarItem));

calendar.addCalendarListener(new CalendarAdapter()
{
	JLabel renderer = new JLabel();

	@Override
	public void draw(CalendarDrawEvent e)
	{
		e.getGraphics().setPaint(Color.green);
		e.getGraphics().fill(e.getBounds());

		renderer.setBounds(e.getBounds());
		renderer.setText(e.getItem().getHeaderText());

		Graphics2D g = (Graphics2D)e.getGraphics().create();
		g.translate(e.getBounds().x, e.getBounds().y);
		renderer.paint(g);
		g.dispose();
	}
});
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3410
Joined: Oct 19th, 2005
Re: Background color and html
Reply #2 - Aug 13th, 2022 at 4:51pm
Print Post  
New build here lets you custom-draw just the text, setting event.Handled to prevent standard text rendering:
https://mindfusion.eu/Forum/YaBB.pl?num=1660408551

Code
Select All
calendar.setCustomDraw(
    EnumSet.of(CustomDrawElements.ItemHeaderText));

calendar.addCalendarListener(new CalendarAdapter()
{
	JLabel renderer = new JLabel();

	@Override
	public void draw(CalendarDrawEvent e)
	{
		if (e.getText().startsWith("<html>"))
		{
			renderer.setBounds(e.getBounds());
			renderer.setText(e.getItem().getHeaderText());

			int centerDx = e.getBounds().width / 2 - renderer.getPreferredSize().width / 2;

			Graphics2D g = (Graphics2D)e.getGraphics().create();
			g.translate(e.getBounds().x + centerDx, e.getBounds().y);
			renderer.paint(g);
			g.dispose();

			e.setHandled(true);
		}
	}
});
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint