Form can't scroll when contains list lwuit - list

Here's my code:
public Form getMenuForm()
{
if ( menuForm == null )
{
Form menuForm = new Form( "Tracking Main Menu" );
menuForm.setLayout( new BoxLayout( BoxLayout.Y_AXIS ) );
menuForm.setScrollable( true );
menuForm.setScrollableY( true );
menuForm.addComponent( this.getMenuList() );
for(int i=0;i<30;i++)
{
Label lblTest = new Label("hello guys");
menuForm.addComponent( lblTest );
}
menuForm.addCommand( new Command( "Exit" ) );
menuForm.setTransitionOutAnimator( CommonTransitions.createSlide( CommonTransitions.SLIDE_HORIZONTAL, true,
200 ) );
menuForm.addCommandListener( this );
}
return menuForm;
}
public List getMenuList()
{
String[] menuItems = { "Find Person", "Person Registration", "Message", "Setting" };
if ( menuList == null )
{
menuList = new List( menuItems );
menuList.setListCellRenderer( new DefaultListCellRenderer( false ) );
menuList.setSmoothScrolling( true );
menuList.setFixedSelection( List.FIXED_NONE );
menuList.addActionListener( this );
}
return menuList;
}
I only can select 4 options of list, and I CAN'T scroll down to see the bottom of screen. Do I miss something here, please help me...

You need to set menuForm to scrollable false and let the list's scrollability take over. You have nested scrollables one in another and that produces a bad user experience.

Maybe you need to do this:
menuList.setScroable(true);

Related

Compose desktop(JVM) BasicTextField, Korean input duplicating

I'm implementing a simple search input field on Compose desktop.
My code looks as below.
BasicTextField(
modifier = Modifier.align(Alignment.CenterVertically).onPreviewKeyEvent {
if(it.key == Key.Enter && it.type == KeyEventType.KeyDown){
println("enter down: $textFieldState")
true
}else {
false
}
},
value = textFieldState,
onValueChange = { input ->
textFieldState = input
},
textStyle = TextStyle(
fontSize = 14.sp,
textAlign = TextAlign.Start,
fontWeight = FontWeight.Normal,
fontFamily = NotoSans,
color = Color.Black
),
maxLines = 1,
decorationBox = { innerTextField ->
Row(modifier = Modifier.fillMaxWidth()) {
if (textFieldState.isEmpty()) {
Text(
text = "Search with user name.",
fontSize = 14.sp,
color = Color(0xFF909ba9),
textAlign = TextAlign.Start,
fontWeight = FontWeight.Normal,
fontFamily = NotoSans,
modifier = Modifier.fillMaxWidth()
.align(Alignment.CenterVertically),
)
}
}
innerTextField()
}
)
This code will create a textfield which has 1 max lines.
It works without any problem on english inputs.
But when I type in Korean inputs, keys such as space, enter, or even numbers will duplicate the last Korean character. For example, in english, if I type in H, I, !,
it will be HII!.
Is there some locale settings that can be done to the textField?
I found no working solution in here or in the Compose multiplatform git issue page. I found a workaround using SwingPanel and JTextField.
SwingPanel(background = Color(0xFFf5f6f6), modifier = Modifier.fillMaxSize(), factory = {
//Some JTextfield I've obtaines from stackoverflow to show place holder text.
//Can be replaced to JTextField(columnCount:Int)
HintTextField("Enter in name",1).apply {
background = java.awt.Color(0xf5, 0xf6, 0xf6)
border = null
}
}, update = {
//SimpleDocumentListener is an implementation of DocumentListener.
//Which means it can be replaced by it.
it.document.addDocumentListener(object : SimpleDocumentListener{
override fun update(e: DocumentEvent) {
try{
val text = it.text
textFieldState = text
} catch(e : Exception) {
e.printStackTrace()
}
}
})
//I need an enter key to trigger some search logics.
//textFieldState seems to print the value as I intended
it.addKeyListener(object : KeyAdapter(){
override fun keyPressed(e: KeyEvent?) {
if(e?.keyCode == KeyEvent.VK_ENTER){
println("ENTER : $textFieldState")
}
}
})
})
Really hope the compose multiplatform team comes up with a better solution.

How to prevent inheriting styles from previous bullet in Slate.js?

Go to slate example https://www.slatejs.org/examples/richtext and create bulleted list.
If you change the style by making the text bold, italic or to any other style midway, the style carry forwards to the next bullet on pressing enter.
Is there any way to prevent this?
Problem reproduction image
This is what I have in handleKeyDown
const handleKeyDown = (event) => {
// other code
if (
event.key === 'Enter' &&
!(
SlateHelpers.isBlockActive(editor, 'bulleted-list') ||
SlateHelpers.isBlockActive(editor, 'numbered-list')
)
) {
event.preventDefault();
const newLine = {
type: 'paragraph',
children: [{ text: '', marks: [] }],
};
Transforms.insertNodes(editor, newLine);
}
if (
event.key === 'Enter' &&
(SlateHelpers.isBlockActive(editor, 'bulleted-list') ||
SlateHelpers.isBlockActive(editor, 'numbered-list'))
) {
const [block] = SlateEditor.node(editor, editor.selection);
if (block.text === '') {
event.preventDefault();
if (SlateHelpers.isBlockActive(editor, 'bulleted-list')) {
SlateHelpers.toggleBlock(editor, 'bulleted-list');
}
if (SlateHelpers.isBlockActive(editor, 'numbered-list')) {
SlateHelpers.toggleBlock(editor, 'numbered-list');
}
}
}
// other code
}
Which is being passed like so
<Editable
renderElement={renderElement}
renderLeaf={renderLeaf}
onKeyDown={handleKeyDown}
spellCheck={false}
/>

How would you go about placing boxes correctly

I am trying to make a datepicker with dates placed beneath the name of the days of the week. But I can't really get the spacing and the placement correct. don't really know what would make it possible to make the placement modifyable during run either because I mean if a month starts on a Wednesday the first date must align with Wednesday instead of Monday or well Sunday.
Here is my code:
val datesList = listOf<String>("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var dayCounter: Int = 1
var week: Int = 1
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) {
datesList.forEach {
Text(text = it.toString().substring(0,3))
}
}
while (dayCounter <= 31){
Row(modifier = Modifier.fillMaxWidth().padding(5.dp)) {
for (i in week..7){
if(dayCounter <= 31){
Box(contentAlignment = Alignment.Center, modifier = Modifier.background(Color.Red , CircleShape).padding(10.dp)) {
Text(text = dayCounter++.toString())
}
}
}
}
}
I have already tried with padding but that just stretches the boxes. and aspectratio wont work either because of the different amount of dates on each row. So I'm kinda stuck will someone please help?
I think this is what you want...
#Composable
fun DatePicker() {
val datesList = listOf<String>("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
var dayCounter: Int = 1
var week: Int = 1
Column(Modifier.fillMaxWidth()) {
Row(
Modifier
.fillMaxWidth()
.padding(5.dp),
horizontalArrangement = Arrangement.Center
) {
datesList.forEach {
Box(
Modifier
.weight(1f)
.padding(5.dp),
contentAlignment = Alignment.Center
) {
Text(text = it.substring(0, 3))
}
}
}
var initWeekday = 3 // wednesday
while (dayCounter <= 31) {
Row(
Modifier
.fillMaxWidth()
.padding(5.dp),
) {
if (initWeekday > 0) {
repeat(initWeekday) {
Spacer(modifier = Modifier.weight(1f))
}
}
for (i in week..(7 - initWeekday)) {
if (dayCounter <= 31) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.weight(1f)
.background(Color.Red, CircleShape)
.padding(10.dp)
) {
Text(text = dayCounter++.toString())
}
} else {
Spacer(modifier = Modifier.weight(1f))
}
}
initWeekday = 0
}
}
}
}
Here's the result:

Endless/Carousel horizontal(Lazyrow) scrollview

I have made a lazyrow (horizontal) scroll with 10 items. My problem now is that when I scroll to item number 10, it stops. And I want it to go back to item number 1 again like a carousel. Does anyone know this? Here is my code for the 10 items:
//Horizontal Scroll view
item {
LazyRow {
items(10) { count->
Card(
modifier = Modifier
.width(110.dp)
.height(140.dp)
.padding(10.dp, 5.dp, 5.dp, 0.dp)
.clip(RoundedCornerShape(10.dp))
.background(Color.White),
elevation = 5.dp
) {
Column(
modifier = Modifier.padding(5.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Image(
painter = painterResource(id = hi.imageId),
contentDescription = "profile Image",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(60.dp)
.clip(CircleShape)
)
Spacer(modifier = Modifier.padding(5.dp))
Text(
text = hi.talk,
color = Color.Black,
fontWeight = FontWeight.Bold,
fontSize = 16.sp)
}
}
}
}
}
I'm pretty new to kotlin, so it is taking some fair time to learn. I couldn't find anything related to this in Jetpack Compose, and it is hard for me to convert from Java.

Changing icon of wxToolBarToolBase on toggle event

I have a toggle button in a wxToolBar.
I'd like the button to show two different icons according its state (one icon when it's "pressed" and another when it's "released").
I tried this:
// toolbar setup:
muteBtn = toolBar -> AddCheckTool(
ID_MUTE_BTN,
wxT( "Mute" ),
wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
wxT( "Enable/Disable sounds" ),
wxT( "Enable/Disable sounds" )
);
...
// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
if ( event.IsChecked() )
{
Mute();
muteBtn -> SetNormalBitmap( wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
}
else
{
Unmute();
muteBtn -> SetNormalBitmap( wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
}
// also tried refresh and update without success:
// toolBar -> Refresh();
// toolBar -> Update();
}
but the behavior is not the one I expect. Instead of:
startup icon: unmute.png
after first click: mute.png (Mute() called)
after second click: unmute.png (Unmute() called)
after thirth click: mute.png (Mute() called)
...
I got:
startup icon: unmute.png
after first click: unmute.png (Mute() called)
after second click: mute.png (Unmute() called)
after thirth click: unmute.png (Mute() called)
...
It seems that inside the event handler I change the icon but the bitmap is drawn only at the next click event.
I also tried adding wxToolBar::Refresh() and wxToolBar::Update() [see snippet] withouth success.
How can I get the correct behaviour?
The developers of wx confirmed that wxToolBarToolBase::SetNormalBitmap() should not be used.
I solved the problem by using the method wxToolBar::SetToolNormalBitmap:
// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
if ( event.IsChecked() )
{
Mute();
toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
}
else
{
Unmute();
toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
}
}